From b82a40f753bd7fba287ab07024b495b25d455fed Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 3 Jul 2022 12:57:29 +0300 Subject: [PATCH 1/2] test_runner: wait for stderr and stdout to complete --- lib/internal/main/test_runner.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/main/test_runner.js b/lib/internal/main/test_runner.js index 0a47535fccfd51..a8ef574f82b3f3 100644 --- a/lib/internal/main/test_runner.js +++ b/lib/internal/main/test_runner.js @@ -7,6 +7,7 @@ const { ArrayPrototypeSlice, ArrayPrototypeSort, Promise, + PromiseAll, SafeSet, } = primordials; const { @@ -14,6 +15,7 @@ const { } = require('internal/bootstrap/pre_execution'); const { spawn } = require('child_process'); const { readdirSync, statSync } = require('fs'); +const { finished } = require('internal/streams/end-of-stream'); const console = require('internal/console/global'); const { codes: { @@ -126,9 +128,10 @@ function runTestFile(path) { stderr += chunk; }); - child.once('exit', (code, signal) => { + child.once('exit', async (code, signal) => { if (code !== 0 || signal !== null) { if (!err) { + await PromiseAll([finished(child.stderr), finished(child.stdout)]); err = new ERR_TEST_FAILURE('test failed', kSubtestsFailed); err.exitCode = code; err.signal = signal; From e48d3eccbd6c58e30343fe9766bf9e700afb940b Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Mon, 4 Jul 2022 23:45:19 +0300 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Antoine du Hamel --- lib/internal/main/test_runner.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/internal/main/test_runner.js b/lib/internal/main/test_runner.js index a8ef574f82b3f3..ccd869d90968e2 100644 --- a/lib/internal/main/test_runner.js +++ b/lib/internal/main/test_runner.js @@ -8,6 +8,7 @@ const { ArrayPrototypeSort, Promise, PromiseAll, + SafeArrayIterator, SafeSet, } = primordials; const { @@ -131,7 +132,7 @@ function runTestFile(path) { child.once('exit', async (code, signal) => { if (code !== 0 || signal !== null) { if (!err) { - await PromiseAll([finished(child.stderr), finished(child.stdout)]); + await PromiseAll(new SafeArrayIterator([finished(child.stderr), finished(child.stdout)])); err = new ERR_TEST_FAILURE('test failed', kSubtestsFailed); err.exitCode = code; err.signal = signal;