node/test/parallel/test-child-process-exec-timeout-not-expired.js
Joyee Cheung fc9d44c8ac
test: deflake child process exec timeout tests
On Windows it might take too long for the parent to start the
communication with a child process, so by the time the parent
starts its own timer, the child process might have already
completed running, and the parent in those tests won't have a
chance to terminate these child processes after the timeout.
To address this issue, raise the time for which the child is
supposed to run to make sure that the parent starts
its own timer before the child terminates in the tests.
Also, split the test into smaller ones to reduce the overhead.

PR-URL: https://github.com/nodejs/node/pull/44390
Refs: https://github.com/nodejs/reliability/issues/356
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2022-09-01 02:31:34 +08:00

35 lines
870 B
JavaScript

'use strict';
// Test exec() when a timeout is set, but not expired.
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const {
cleanupStaleProcess,
logAfterTime
} = require('../common/child_process');
const kTimeoutNotSupposedToExpire = 2 ** 30;
const childRunTime = common.platformTimeout(100);
// The time spent in the child should be smaller than the timeout below.
assert(childRunTime < kTimeoutNotSupposedToExpire);
if (process.argv[2] === 'child') {
logAfterTime(childRunTime);
return;
}
const cmd = `"${process.execPath}" "${__filename}" child`;
cp.exec(cmd, {
timeout: kTimeoutNotSupposedToExpire
}, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), 'child stdout');
assert.strictEqual(stderr.trim(), 'child stderr');
}));
cleanupStaleProcess(__filename);