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 <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
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‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const{
1818
RegExpPrototypeExec,
1919
StringPrototypeSplit,
2020
}=primordials;
21+
letdebug=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+
constoptions={
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
}
Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,26 @@
11
'use strict';
2-
constcommon=require('../common');
3-
consttmpdir=require('../common/tmpdir');
4-
const{ deepStrictEqual, strictEqual }=require('node:assert');
2+
require('../common');
3+
constfixtures=require('../common/fixtures');
4+
constassert=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+
constcwd=fixtures.path('test-runner','default-behavior');
8+
constenv={ ...process.env,'NODE_DEBUG': 'test_runner'};
99

10-
functioncreateTestFile(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+
constargs=['--test'];
12+
constcp=spawnSync(process.execPath,args,{ cwd, env });
13+
assert.match(cp.stderr.toString(),/concurrency:true,/);
2314
});
2415

25-
test('concurrency of one',()=>{
26-
constcp=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+
constargs=['--test','--test-concurrency=1'];
18+
constcp=spawnSync(process.execPath,args,{ cwd, env });
19+
assert.match(cp.stderr.toString(),/concurrency:1,/);
3420
});
3521

36-
test('concurrency of two',()=>{
37-
constcp=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+
constargs=['--test','--test-concurrency=2'];
24+
constcp=spawnSync(process.execPath,args,{ cwd, env });
25+
assert.match(cp.stderr.toString(),/concurrency:2,/);
4526
});

0 commit comments

Comments
(0)