Skip to content

Commit

Permalink
Don't restart timeout timer when receiving events from timed out workers
Browse files Browse the repository at this point in the history
It can take longer for workers to exit than the timeout period, in which
case restarting the timeout timer just causes it to fire again.
  • Loading branch information
novemberborn committed Apr 2, 2018
1 parent 66b5daf commit 3b1324b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Api extends Emittery {
const failFast = apiOptions.failFast === true;
let bailed = false;
const pendingWorkers = new Set();
const timedOutWorkerFiles = new Set();
let restartTimer;
if (apiOptions.timeout) {
const timeout = ms(apiOptions.timeout);
Expand All @@ -64,6 +65,7 @@ class Api extends Emittery {
}

for (const worker of pendingWorkers) {
timedOutWorkerFiles.add(worker.file);
worker.exit();
}

Expand Down Expand Up @@ -98,8 +100,11 @@ class Api extends Emittery {
}

runStatus.on('stateChange', record => {
// Restart the timer whenever there is activity.
restartTimer();
if (record.testFile && !timedOutWorkerFiles.has(record.testFile)) {
// Restart the timer whenever there is activity from workers that
// haven't already timed out.
restartTimer();
}

if (failFast && (record.type === 'hook-failed' || record.type === 'test-failed' || record.type === 'worker-failed')) {
// Prevent new test files from running once a test has failed.
Expand Down
1 change: 1 addition & 0 deletions lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module.exports = (file, opts, execArgv) => {
return emitter.on('stateChange', listener);
},

file,
promise
};
};
1 change: 1 addition & 0 deletions profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ babelConfigHelper.build(process.cwd(), cacheDir, babelConfigHelper.validate(conf

const runStatus = new RunStatus([file]);
runStatus.observeWorker({
file,
onStateChange(listener) {
const emit = evt => listener(Object.assign(evt, {testFile: file}));
process.send = data => {
Expand Down

0 comments on commit 3b1324b

Please sign in to comment.