From 9efb3ac3a716ea2bf2747137006d651c3bf248d3 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 8 Jan 2018 16:52:58 -0800 Subject: [PATCH] Fix this.timeout not actually applying the timeout within it blocks (#21079) --- src/harness/parallel/host.ts | 4 +++- src/harness/parallel/worker.ts | 34 +++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/harness/parallel/host.ts b/src/harness/parallel/host.ts index 56b8df5ecfe..59105cd5b08 100644 --- a/src/harness/parallel/host.ts +++ b/src/harness/parallel/host.ts @@ -151,7 +151,7 @@ namespace Harness.Parallel.Host { let currentTimeout = defaultTimeout; const killChild = () => { child.kill(); - console.error(`Worker exceeded timeout ${child.currentTasks && child.currentTasks.length ? `while running test '${child.currentTasks[0].file}'.` : `during test setup.`}`); + console.error(`Worker exceeded ${currentTimeout}ms timeout ${child.currentTasks && child.currentTasks.length ? `while running test '${child.currentTasks[0].file}'.` : `during test setup.`}`); return process.exit(2); }; let timer = setTimeout(killChild, currentTimeout); @@ -176,6 +176,7 @@ namespace Harness.Parallel.Host { return process.exit(2); } case "timeout": { + clearTimeout(timer); if (data.payload.duration === "reset") { currentTimeout = timeoutStack.pop() || defaultTimeout; } @@ -183,6 +184,7 @@ namespace Harness.Parallel.Host { timeoutStack.push(currentTimeout); currentTimeout = data.payload.duration; } + timer = setTimeout(killChild, currentTimeout); // Reset timeout on timeout update, for when a timeout changes while a suite is executing break; } case "progress": diff --git a/src/harness/parallel/worker.ts b/src/harness/parallel/worker.ts index 00fbcd23ebb..1902ff70b19 100644 --- a/src/harness/parallel/worker.ts +++ b/src/harness/parallel/worker.ts @@ -128,6 +128,8 @@ namespace Harness.Parallel.Worker { skip() { return this; }, timeout(n) { timeout = n as number; + const timeoutMsg: ParallelTimeoutChangeMessage = { type: "timeout", payload: { duration: timeout } }; + process.send(timeoutMsg); return this; }, retries() { return this; }, @@ -145,20 +147,22 @@ namespace Harness.Parallel.Worker { } } if (callback.length === 0) { - setTimeoutAndExecute(timeout, () => { - try { - // TODO: If we ever start using async test completions, polyfill promise return handling - callback.call(fakeContext); + try { + // TODO: If we ever start using async test completions, polyfill promise return handling + callback.call(fakeContext); + } + catch (error) { + errors.push({ error: error.message, stack: error.stack, name: [...namestack] }); + return; + } + finally { + namestack.pop(); + if (timeout !== undefined) { + const timeoutMsg: ParallelTimeoutChangeMessage = { type: "timeout", payload: { duration: "reset" } }; + process.send(timeoutMsg); } - catch (error) { - errors.push({ error: error.message, stack: error.stack, name: [...namestack] }); - return; - } - finally { - namestack.pop(); - } - passing++; - }); + } + passing++; } else { // Uses `done` callback @@ -183,6 +187,10 @@ namespace Harness.Parallel.Worker { } finally { namestack.pop(); + if (timeout !== undefined) { + const timeoutMsg: ParallelTimeoutChangeMessage = { type: "timeout", payload: { duration: "reset" } }; + process.send(timeoutMsg); + } } if (!completed) { errors.push({ error: "Test completes asynchronously, which is unsupported by the parallel harness", stack: "", name: [...namestack] });