Bug 1343749. Part 1 - Let MediaTestManager manage timeout of each test. r=jya

MozReview-Commit-ID: HocDk9FCi6Q

--HG--
extra : rebase_source : 71e25e29df791f02ad250ccc24d2045989fcd9e9
extra : source : 7a4c4e11c89dbf84a75a40374e412e96abc0b108
This commit is contained in:
JW Wang 2017-03-02 12:44:40 +08:00
Родитель f62798efe1
Коммит a4eb89f891
1 изменённых файлов: 19 добавлений и 0 удалений

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

@ -1611,6 +1611,10 @@ const DEBUG_TEST_LOOP_FOREVER = false;
// or end the mochitest if all the tests are done.
function MediaTestManager() {
// Set a very large timeout to prevent Mochitest timeout.
// Instead MediaTestManager will manage timeout of each test.
SimpleTest.requestLongerTimeout(1000);
// Return how many seconds elapsed since |begin|.
function elapsedTime(begin) {
var end = new Date();
@ -1634,6 +1638,7 @@ function MediaTestManager() {
this.isShutdown = false;
this.numTestsRunning = 0;
this.handlers = {};
this.timers = {};
// Always wait for explicit finish.
SimpleTest.waitForExplicitFinish();
@ -1660,6 +1665,14 @@ function MediaTestManager() {
this.tokens.push(token);
this.numTestsRunning++;
this.handlers[token] = handler;
var onTimeout = function() {
ok(false, `${token} timed out!`);
this.finished(token);
}.bind(this);
// Default timeout to 180s for each test.
this.timers[token] = setTimeout(onTimeout, 180000);
is(this.numTestsRunning, this.tokens.length,
"[started " + token + " t=" + elapsedTime(this.startTime) + "] Length of array should match number of running tests");
}
@ -1675,6 +1688,12 @@ function MediaTestManager() {
this.tokens.splice(i, 1);
}
if (this.timers[token]) {
// Cancel the timer when the test finishes.
clearTimeout(this.timers[token]);
this.timers[token] = null;
}
info("[finished " + token + "] remaining= " + this.tokens);
this.numTestsRunning--;
is(this.numTestsRunning, this.tokens.length,