Bug 911216 - Part 20: Make aboutPerformance.js robust against timing issues when running in mochitest harness. r=yoric

This commit is contained in:
Till Schneidereit 2016-05-26 16:13:47 +02:00
Родитель 4c5b726b0c
Коммит 72e617b1ca
1 изменённых файлов: 23 добавлений и 3 удалений

Просмотреть файл

@ -115,8 +115,28 @@ let tabFinder = {
}
};
/**
* Returns a Promise that's resolved after the next turn of the event loop.
*
* Just returning a resolved Promise would mean that any `then` callbacks
* would be called right after the end of the current turn, so `setTimeout`
* is used to delay Promise resolution until the next turn.
*
* In mochi tests, it's possible for this to be called after the
* about:performance window has been torn down, which causes `setTimeout` to
* throw an NS_ERROR_NOT_INITIALIZED exception. In that case, returning
* `undefined` is fine.
*/
function wait(ms = 0) {
return new Promise(resolve => setTimeout(resolve, ms));
try {
let resolve;
let p = new Promise(resolve_ => {resolve = resolve_});
setTimeout(resolve, ms);
return p;
} catch (e) {
dump("WARNING: wait aborted because of an invalid Window state in aboutPerformance.js.\n");
return;
}
}
/**
@ -398,7 +418,7 @@ var State = {
}
this._latest = this._oldest = yield this._monitor.promiseSnapshot();
this._buffer.push(this._oldest);
yield new Promise(resolve => setTimeout(resolve, BUFFER_SAMPLING_RATE_MS * 1.1));
yield wait(BUFFER_SAMPLING_RATE_MS * 1.1);
}
@ -935,6 +955,6 @@ var go = Task.async(function*() {
window.addEventListener("unload", () => Services.obs.removeObserver(testUpdate, TEST_DRIVER_TOPIC));
yield Control.update();
yield new Promise(resolve => setTimeout(resolve, BUFFER_SAMPLING_RATE_MS * 1.1));
yield wait(BUFFER_SAMPLING_RATE_MS * 1.1);
yield Control.update();
});