Skip to content

Commit e4a1b3d

Browse files
committed
test: fix flaky test-runner-cli-concurrency.js
This test was flaky on Windows when trying to clean up the tmp directory between tests. This commit updates the test to not delete anything between tests. Fixes: #50101
1 parent ac2a68c commit e4a1b3d

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

test/parallel/test-runner-cli-concurrency.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,56 @@ const common = require('../common');
33
const tmpdir = require('../common/tmpdir');
44
const { deepStrictEqual, strictEqual } = require('node:assert');
55
const { spawnSync } = require('node:child_process');
6-
const { readdirSync, writeFileSync } = require('node:fs');
6+
const { mkdirSync, readdirSync, writeFileSync } = require('node:fs');
77
const { join } = require('node:path');
8-
const { beforeEach, test } = require('node:test');
8+
const { test } = require('node:test');
99

1010
function createTestFile(name) {
11-
writeFileSync(join(tmpdir.path, name), `
11+
const path = join(tmpdir.path, name);
12+
writeFileSync(path, `
1213
const fs = require('node:fs');
14+
const { join } = require('node:path');
1315
14-
fs.unlinkSync(__filename);
16+
fs.writeFileSync(join(process.cwd(), '${name}.out'), 'x');
1517
setTimeout(() => {}, 1_000_000_000);
1618
`);
19+
return path;
1720
}
1821

19-
beforeEach(() => {
20-
tmpdir.refresh();
21-
createTestFile('test-1.js');
22-
createTestFile('test-2.js');
23-
});
22+
let cnt = 0;
23+
function nextDir() {
24+
const path = join(tmpdir.path, String(cnt));
25+
cnt++;
26+
mkdirSync(path);
27+
return path;
28+
}
29+
30+
tmpdir.refresh();
31+
const test1 = createTestFile('test-1.js');
32+
const test2 = createTestFile('test-2.js');
2433

2534
test('concurrency of one', () => {
26-
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=1'], {
27-
cwd: tmpdir.path,
35+
const cwd = nextDir();
36+
const args = ['--test', '--test-concurrency=1', test1, test2];
37+
const cp = spawnSync(process.execPath, args, {
38+
cwd,
2839
timeout: common.platformTimeout(1000),
2940
});
3041

3142
strictEqual(cp.stderr.toString(), '');
3243
strictEqual(cp.error.code, 'ETIMEDOUT');
33-
deepStrictEqual(readdirSync(tmpdir.path), ['test-2.js']);
44+
deepStrictEqual(readdirSync(cwd), ['test-1.js.out']);
3445
});
3546

3647
test('concurrency of two', () => {
37-
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=2'], {
38-
cwd: tmpdir.path,
48+
const cwd = nextDir();
49+
const args = ['--test', '--test-concurrency=2', test1, test2];
50+
const cp = spawnSync(process.execPath, args, {
51+
cwd,
3952
timeout: common.platformTimeout(1000),
4053
});
4154

4255
strictEqual(cp.stderr.toString(), '');
4356
strictEqual(cp.error.code, 'ETIMEDOUT');
44-
deepStrictEqual(readdirSync(tmpdir.path), []);
57+
deepStrictEqual(readdirSync(cwd), ['test-1.js.out', 'test-2.js.out']);
4558
});

0 commit comments

Comments
 (0)