Skip to content

Commit 87ca9a6

Browse files
Trottitaloacasas
authored andcommitted
test: fix flaky child-process-exec-kill-throws
This is a fix for test-child-process-exec-kill-throws which is currently flaky on Windows. A bug in the test was causing the child process to fail for reasons other than those intended by the test. Instead of failing for exceeding the `maxBuffer` setting, the test was failing because it was trying to load `internal/child_process` without being passed the `expose-internals` flag. Move that module to where only the parent process (which gets the flag) loads it. Additionally, improve an assertion message to help debug problems like this. PR-URL: #12111 Fixes: #12053 Reviewed-By: Richard Lau <[email protected]>
1 parent fdf76d5 commit 87ca9a6

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

test/parallel/parallel.status

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ prefix parallel
77
[true] # This section applies to all platforms
88

99
[$system==win32]
10-
# See https://github.com/nodejs/node/issues/12053, this test may be exposing a
11-
# genuine bug with kill() on Windows.
12-
test-child-process-exec-kill-throws : PASS,FLAKY
1310

1411
[$system==linux]
1512

test/parallel/test-child-process-exec-kill-throws.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
const common = require('../common');
44
const assert = require('assert');
55
const cp = require('child_process');
6-
const internalCp = require('internal/child_process');
76

87
if (process.argv[2] === 'child') {
9-
// Keep the process alive and printing to stdout.
10-
setInterval(() => { console.log('foo'); }, 1);
8+
// Since maxBuffer is 0, this should trigger an error.
9+
console.log('foo');
1110
} else {
11+
const internalCp = require('internal/child_process');
12+
1213
// Monkey patch ChildProcess#kill() to kill the process and then throw.
1314
const kill = internalCp.ChildProcess.prototype.kill;
1415

@@ -21,7 +22,7 @@ if (process.argv[2] === 'child') {
2122
const options = { maxBuffer: 0 };
2223
const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
2324
// Verify that if ChildProcess#kill() throws, the error is reported.
24-
assert(/^Error: mock error$/.test(err));
25+
assert.strictEqual(err.message, 'mock error', err);
2526
assert.strictEqual(stdout, '');
2627
assert.strictEqual(stderr, '');
2728
assert.strictEqual(child.killed, true);

0 commit comments

Comments
 (0)