mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Fix this.timeout not actually applying the timeout within it blocks (#21079)
This commit is contained in:
@@ -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":
|
||||
|
||||
@@ -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] });
|
||||
|
||||
Reference in New Issue
Block a user