Bug 1407826 - minimizeMemoryUsage and flush the event loop after reload step and teardown. r=bgrins,jmaher
MozReview-Commit-ID: E9weZ4Yycz0
--- a/testing/talos/talos/tests/devtools/addon/content/damp.js
+++ b/testing/talos/talos/tests/devtools/addon/content/damp.js
@@ -1,11 +1,51 @@
const { Services } = Components.utils.import("resource://gre/modules/Services.jsm", {});
const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
+const gMgr = Cc['@mozilla.org/memory-reporter-manager;1'].getService(Ci.nsIMemoryReporterManager);
+
+// Flush any action pending on the event loop
+// Return the number of processed events, if any.
+function processPendingEvents() {
+ let loops = 0;
+ while (Services.tm.currentThread.hasPendingEvents()) {
+ Services.tm.currentThread.processNextEvent(true);
+ loops++;
+ }
+ return loops;
+}
+// Garbage collect everything.
+function garbageCollect() {
+ dump("Garbage collect\n");
+
+ // Minimize memory usage
+ Services.obs.notifyObservers(null, "child-mmu-request");
+ return new Promise(done => {
+ gMgr.minimizeMemoryUsage(done);
+ });
+}
+// Function to help waiting for all previous asynchronous action to be finished,
+// and also garbage collect things to avoid having a GC cause by previous test.
+async function settle() {
+ let start = performance.now();
+ await garbageCollect();
+
+ dump("Flush event loop\n");
+ // Wait for the event loop to be empty 10 times in a row for 500ms
+ let wait = 10;
+ while(wait > 0) {
+ while(processPendingEvents() > 0) {
+ wait = 10;
+ }
+ await new Promise(done => setTimeout(done, 50));
+ wait--;
+ }
+ dump("Settled in " + Math.round(performance.now() - start) + "ms\n");
+}
XPCOMUtils.defineLazyGetter(this, "require", function() {
let { require } =
Components.utils.import("resource://devtools/shared/Loader.jsm", {});
return require;
});
XPCOMUtils.defineLazyGetter(this, "gDevTools", function() {
let { gDevTools } = require("devtools/client/framework/devtools");
@@ -442,16 +482,17 @@ async _consoleOpenWithCachedMessagesTest
let {time} = await this.closeToolbox();
this._results.push({name: name + ".close.DAMP", value: time });
},
async reloadPageAndLog(name, onReload) {
dump("Reload page on '" + name + "'\n");
let {time} = await this.reloadPage(onReload);
this._results.push({name: name + ".reload.DAMP", value: time });
+ await settle();
},
async _coldInspectorOpen() {
await this.testSetup(SIMPLE_URL);
await this.openToolboxAndLog("cold.inspector", "inspector");
await this.closeToolbox();
await this.testTeardown();
},
@@ -578,20 +619,21 @@ async _consoleOpenWithCachedMessagesTest
testSetup: Task.async(function* (url) {
let tab = yield this.addTab(url);
yield new Promise(resolve => {
setTimeout(resolve, this._config.rest);
});
return tab;
}),
- testTeardown: Task.async(function* (url) {
+ async testTeardown(url) {
this.closeCurrentTab();
+ await settle();
this._nextCommand();
- }),
+ },
// Everything below here are common pieces needed for the test runner to function,
// just copy and pasted from Tart with /s/TART/DAMP
_win: undefined,
_dampTab: undefined,
_results: [],
_config: {subtests: [], repeat: 1, rest: 100},