From 3b1324b841b9415788cd47254ad92b0a011507ce Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sun, 11 Mar 2018 16:26:08 +0000 Subject: [PATCH] Don't restart timeout timer when receiving events from timed out workers 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. --- api.js | 9 +++++++-- lib/fork.js | 1 + profile.js | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api.js b/api.js index acc05d2cb..5342377eb 100644 --- a/api.js +++ b/api.js @@ -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); @@ -64,6 +65,7 @@ class Api extends Emittery { } for (const worker of pendingWorkers) { + timedOutWorkerFiles.add(worker.file); worker.exit(); } @@ -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. diff --git a/lib/fork.js b/lib/fork.js index 8795c7538..eb2399f2b 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -120,6 +120,7 @@ module.exports = (file, opts, execArgv) => { return emitter.on('stateChange', listener); }, + file, promise }; }; diff --git a/profile.js b/profile.js index 65278ffbd..8c6ba7437 100644 --- a/profile.js +++ b/profile.js @@ -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 => {