Bug 1263409 - In addon performance alert tests, poll to see if we get desired jank measurement. r=Yoric, a=test-only
authorWilliam Lachance <wlachance@mozilla.com>
Wed, 31 Aug 2016 15:47:12 -0400
changeset 350072 8224f8bc9ebde49a01063402615a53168aa4694b
parent 350071 47a382f6603005ef82df370924880d9471990f52
child 350073 d76058fbf56fd00bc0e69136a1f8ae73047efe74
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric, test-only
bugs1263409
milestone50.0a2
Bug 1263409 - In addon performance alert tests, poll to see if we get desired jank measurement. r=Yoric, a=test-only MozReview-Commit-ID: 3k6AZO5QJTp
toolkit/components/perfmonitoring/tests/browser/browser_addonPerformanceAlerts.js
toolkit/components/perfmonitoring/tests/browser/browser_addonPerformanceAlerts_2.js
toolkit/components/perfmonitoring/tests/browser/browser_webpagePerformanceAlerts.js
toolkit/components/perfmonitoring/tests/browser/head.js
--- a/toolkit/components/perfmonitoring/tests/browser/browser_addonPerformanceAlerts.js
+++ b/toolkit/components/perfmonitoring/tests/browser/browser_addonPerformanceAlerts.js
@@ -51,17 +51,17 @@ add_task(function* test_install_addon_th
     yield new Promise(resolve => setTimeout(resolve, 100));
     yield addon.run(topic, 10, realListener);
     // Waiting a little – listeners are buffered.
     yield new Promise(resolve => setTimeout(resolve, 100));
 
     Assert.ok(realListener.triggered, `1. The real listener was triggered ${topic}`);
     Assert.ok(universalListener.triggered, `1. The universal listener was triggered ${topic}`);
     Assert.ok(!fakeListener.triggered, `1. The fake listener was not triggered ${topic}`);
-    Assert.ok(realListener.result >= 200000, `1. jank is at least 300ms (${realListener.result/1000}ms) ${topic}`);
+    Assert.ok(realListener.result >= addon.jankThreshold, `1. jank is at least ${addon.jankThreshold/1000}ms (${realListener.result/1000}ms) ${topic}`);
 
     info(`Attempting to remove a performance listener incorrectly, check that this does not hurt our real listener ${topic}`);
     Assert.throws(() => PerformanceWatcher.removePerformanceListener({addonId: addon.addonId}, () => {}));
     Assert.throws(() => PerformanceWatcher.removePerformanceListener({addonId: addon.addonId + "-unbound-id-" + Math.random()}, realListener.listener));
 
     yield addon.run(topic, 10, realListener);
     // Waiting a little – listeners are buffered.
     yield new Promise(resolve => setTimeout(resolve, 300));
--- a/toolkit/components/perfmonitoring/tests/browser/browser_addonPerformanceAlerts_2.js
+++ b/toolkit/components/perfmonitoring/tests/browser/browser_addonPerformanceAlerts_2.js
@@ -13,13 +13,13 @@ add_task(function* test_watch_addon_then
       }
       throw new Error(`I shouldn't have been called with addon ${group.addonId}`);
     });
 
     info("Now install the add-on, *after* having installed the listener");
     let addon = new AddonBurner(addonId);
 
     Assert.ok((yield addon.run(topic, 10, realListener)), `5. The real listener was triggered ${topic}`);
-    Assert.ok(realListener.result >= 200000, `5. jank is at least 200ms (${realListener.result}µs) ${topic}`);
+    Assert.ok(realListener.result >= addon.jankThreshold, `5. jank is at least ${addon.jankThreshold/1000}ms (${realListener.result}µs) ${topic}`);
     realListener.unregister();
     addon.dispose();
   }
 });
--- a/toolkit/components/perfmonitoring/tests/browser/browser_webpagePerformanceAlerts.js
+++ b/toolkit/components/perfmonitoring/tests/browser/browser_webpagePerformanceAlerts.js
@@ -3,17 +3,17 @@
 /**
  * Tests for PerformanceWatcher watching slow web pages.
  */
 
  /**
   * Simulate a slow webpage.
   */
 function WebpageBurner() {
-  CPUBurner.call(this, "http://example.com/browser/toolkit/components/perfmonitoring/tests/browser/browser_compartments.html?test=" + Math.random());
+  CPUBurner.call(this, "http://example.com/browser/toolkit/components/perfmonitoring/tests/browser/browser_compartments.html?test=" + Math.random(), 300000);
 }
 WebpageBurner.prototype = Object.create(CPUBurner.prototype);
 WebpageBurner.prototype.promiseBurnContentCPU = function() {
   return promiseContentResponse(this._browser, "test-performance-watcher:burn-content-cpu", {});
 };
 
 function WebpageListener(windowId, accept) {
   info(`Creating WebpageListener for ${windowId}`);
--- a/toolkit/components/perfmonitoring/tests/browser/head.js
+++ b/toolkit/components/perfmonitoring/tests/browser/head.js
@@ -3,46 +3,48 @@
 
 var { utils: Cu, interfaces: Ci, classes: Cc } = Components;
 
 Cu.import("resource://gre/modules/Promise.jsm", this);
 Cu.import("resource://gre/modules/AddonManager.jsm", this);
 Cu.import("resource://gre/modules/AddonWatcher.jsm", this);
 Cu.import("resource://gre/modules/PerformanceWatcher.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
+Cu.import("resource://testing-common/ContentTaskUtils.jsm", this);
 
 /**
  * Base class for simulating slow addons/webpages.
  */
-function CPUBurner(url) {
+function CPUBurner(url, jankThreshold) {
   info(`CPUBurner: Opening tab for ${url}\n`);
   this.url = url;
   this.tab = gBrowser.addTab(url);
+  this.jankThreshold = jankThreshold;
   let browser = this.tab.linkedBrowser;
   this._browser = browser;
   ContentTask.spawn(this._browser, null, CPUBurner.frameScript);
   this.promiseInitialized = BrowserTestUtils.browserLoaded(browser);
 }
 CPUBurner.prototype = {
   get windowId() {
     return this._browser.outerWindowID;
   },
   /**
-   * Burn CPU until it triggers a listener.
+   * Burn CPU until it triggers a listener with the specified jank threshold.
    */
   run: Task.async(function*(burner, max, listener) {
     listener.reset();
     for (let i = 0; i < max; ++i) {
       yield new Promise(resolve => setTimeout(resolve, 50));
       try {
         yield this[burner]();
       } catch (ex) {
         return false;
       }
-      if (listener.triggered) {
+      if (listener.triggered && listener.result >= this.jankThreshold) {
         return true;
       }
     }
     return false;
   }),
   dispose: function() {
     info(`CPUBurner: Closing tab for ${this.url}\n`);
     gBrowser.removeTab(this.tab);
@@ -156,17 +158,18 @@ AlertListener.prototype = {
     this.result = null;
   },
 };
 
 /**
  * Simulate a slow add-on.
  */
 function AddonBurner(addonId = "fake add-on id: " + Math.random()) {
-  CPUBurner.call(this, `http://example.com/?uri=${addonId}`)
+  this.jankThreshold = 200000;
+  CPUBurner.call(this, `http://example.com/?uri=${addonId}`, this.jankThreshold);
   this._addonId = addonId;
   this._sandbox = Components.utils.Sandbox(Services.scriptSecurityManager.getSystemPrincipal(), { addonId: this._addonId });
   this._CPOWBurner = null;
 
   this._promiseCPOWBurner = new Promise(resolve => {
     this._browser.messageManager.addMessageListener("test-performance-watcher:cpow-init", msg => {
       // Note that we cannot resolve Promises with CPOWs now that they
       // have been outlawed in bug 1233497, so we stash it in the