Skip to content

Commit 0d8faf2

Browse files
authored
test_runner,test: fix flaky test-runner-cli-concurrency.js
This test was flaky on Windows when trying to clean up the tmp directory, probably because it relied on child processes timing out and being killed. This commit updates the test to check for debug output from the test runner. This should be adequate because the original change was effectively: let concurrency = getOptionValue('--test-concurrency') || true; The test runner now logs the value of the concurrency variable. Fixes: #50101 PR-URL: #50108 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent dc1c50b commit 0d8faf2

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

lib/internal/main/test_runner.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const {
1818
RegExpPrototypeExec,
1919
StringPrototypeSplit,
2020
} = primordials;
21+
let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
22+
debug = fn;
23+
});
2124

2225
prepareMainThreadExecution(false);
2326
markBootstrapComplete();
@@ -57,8 +60,15 @@ if (shardOption) {
5760
};
5861
}
5962

60-
run({ concurrency, inspectPort, watch: getOptionValue('--watch'), setup: setupTestReporters, shard })
61-
.on('test:fail', (data) => {
63+
const options = {
64+
concurrency,
65+
inspectPort,
66+
watch: getOptionValue('--watch'),
67+
setup: setupTestReporters,
68+
shard,
69+
};
70+
debug('test runner configuration:', options);
71+
run(options).on('test:fail', (data) => {
6272
if (data.todo === undefined || data.todo === false) {
6373
process.exitCode = kGenericUserError;
6474
}
+18-37
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,26 @@
11
'use strict';
2-
const common = require('../common');
3-
const tmpdir = require('../common/tmpdir');
4-
const { deepStrictEqual, strictEqual } = require('node:assert');
2+
require('../common');
3+
const fixtures = require('../common/fixtures');
4+
const assert = require('node:assert');
55
const { spawnSync } = require('node:child_process');
6-
const { readdirSync, writeFileSync } = require('node:fs');
7-
const { join } = require('node:path');
8-
const { beforeEach, test } = require('node:test');
6+
const { test } = require('node:test');
7+
const cwd = fixtures.path('test-runner', 'default-behavior');
8+
const env = { ...process.env, 'NODE_DEBUG': 'test_runner' };
99

10-
function createTestFile(name) {
11-
writeFileSync(join(tmpdir.path, name), `
12-
const fs = require('node:fs');
13-
14-
fs.unlinkSync(__filename);
15-
setTimeout(() => {}, 1_000_000_000);
16-
`);
17-
}
18-
19-
beforeEach(() => {
20-
tmpdir.refresh();
21-
createTestFile('test-1.js');
22-
createTestFile('test-2.js');
10+
test('default concurrency', async () => {
11+
const args = ['--test'];
12+
const cp = spawnSync(process.execPath, args, { cwd, env });
13+
assert.match(cp.stderr.toString(), /concurrency: true,/);
2314
});
2415

25-
test('concurrency of one', () => {
26-
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=1'], {
27-
cwd: tmpdir.path,
28-
timeout: common.platformTimeout(1000),
29-
});
30-
31-
strictEqual(cp.stderr.toString(), '');
32-
strictEqual(cp.error.code, 'ETIMEDOUT');
33-
deepStrictEqual(readdirSync(tmpdir.path), ['test-2.js']);
16+
test('concurrency of one', async () => {
17+
const args = ['--test', '--test-concurrency=1'];
18+
const cp = spawnSync(process.execPath, args, { cwd, env });
19+
assert.match(cp.stderr.toString(), /concurrency: 1,/);
3420
});
3521

36-
test('concurrency of two', () => {
37-
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=2'], {
38-
cwd: tmpdir.path,
39-
timeout: common.platformTimeout(1000),
40-
});
41-
42-
strictEqual(cp.stderr.toString(), '');
43-
strictEqual(cp.error.code, 'ETIMEDOUT');
44-
deepStrictEqual(readdirSync(tmpdir.path), []);
22+
test('concurrency of two', async () => {
23+
const args = ['--test', '--test-concurrency=2'];
24+
const cp = spawnSync(process.execPath, args, { cwd, env });
25+
assert.match(cp.stderr.toString(), /concurrency: 2,/);
4526
});

0 commit comments

Comments
 (0)