fix(testrunner): properly handle testrunner terminations (#4717)
This patch improves the logic for test runner termination. With this patch: - TestRunner runs all afterEach/afterAll hooks when a termination happens, properly terminating browser instances - TestRunner cleans up all dangling timeout timers so that node.js process is not retained and is free to exit
This commit is contained in:
parent
ad1802188d
commit
eea55bd6c6
@ -35,8 +35,9 @@ class UserCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(...args) {
|
async run(...args) {
|
||||||
|
let timeoutId;
|
||||||
const timeoutPromise = new Promise(resolve => {
|
const timeoutPromise = new Promise(resolve => {
|
||||||
setTimeout(resolve.bind(null, TimeoutError), this.timeout);
|
timeoutId = setTimeout(resolve.bind(null, TimeoutError), this.timeout);
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
return await Promise.race([
|
return await Promise.race([
|
||||||
@ -46,6 +47,8 @@ class UserCallback {
|
|||||||
]);
|
]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return e;
|
return e;
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +195,8 @@ class TestPass {
|
|||||||
return;
|
return;
|
||||||
await this._runHook(workerId, currentSuite, 'beforeAll', state);
|
await this._runHook(workerId, currentSuite, 'beforeAll', state);
|
||||||
for (const child of currentSuite.children) {
|
for (const child of currentSuite.children) {
|
||||||
|
if (this._termination)
|
||||||
|
break;
|
||||||
if (!this._workerDistribution.hasValue(child, workerId))
|
if (!this._workerDistribution.hasValue(child, workerId))
|
||||||
continue;
|
continue;
|
||||||
if (child instanceof Test) {
|
if (child instanceof Test) {
|
||||||
@ -234,8 +239,6 @@ class TestPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _runHook(workerId, suite, hookName, ...args) {
|
async _runHook(workerId, suite, hookName, ...args) {
|
||||||
if (this._termination)
|
|
||||||
return;
|
|
||||||
const hook = suite[hookName];
|
const hook = suite[hookName];
|
||||||
if (!hook)
|
if (!hook)
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user