Skip to content

Commit

Permalink
test_runner: wait for reporter and parser to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Feb 21, 2023
1 parent b85b5ba commit 6a24768
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
ObjectAssign,
ObjectKeys,
PromisePrototypeThen,
SafePromiseAll,
SafePromiseAllReturnVoid,
SafePromiseAllSettledReturnVoid,
SafeMap,
Expand All @@ -24,6 +25,7 @@ const {

const { spawn } = require('child_process');
const { readdirSync, statSync } = require('fs');
const { finished } = require('internal/streams/end-of-stream');
// TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern.
const { createInterface } = require('readline');
const { FilesWatcher } = require('internal/watch_mode/files_watcher');
Expand Down Expand Up @@ -299,7 +301,10 @@ function runTestFile(path, root, inspectPort, filesWatcher) {
subtest.addToReport(ast);
});

const { 0: code, 1: signal } = await once(child, 'exit', { signal: t.signal });
const { 0: { 0: code, 1: signal } } = await SafePromiseAll([
once(child, 'exit', { signal: t.signal }),
finished(parser, { signal: t.signal }),
]);

runningProcesses.delete(path);
runningSubtests.delete(path);
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {
validateUint32,
} = require('internal/validators');
const { setTimeout } = require('timers/promises');
const { setInterval, clearInterval } = require('timers');
const { TIMEOUT_MAX } = require('internal/timers');
const { availableParallelism } = require('os');
const { bigint: hrtime } = process.hrtime;
Expand Down Expand Up @@ -649,6 +650,10 @@ class Test extends AsyncResource {
this.reporter.coverage(this.nesting, kFilename, this.coverage);
}

// In case the event loop has ended and reporter has not drained,
// we use a timer to keep the process alive until the reporter is done.
const handle = setInterval(() => {}, TIMEOUT_MAX);
this.reporter.once('close', () => clearInterval(handle));
this.reporter.push(null);
}
}
Expand Down

0 comments on commit 6a24768

Please sign in to comment.