Skip to content

Commit cfcb759

Browse files
Trottaddaleax
authored andcommitted
test: prepare test-hash-seed for CI
Reduce the time it takes to run test/pummel/test-hash-seed by switching from spawnSync() to spawn(). On my computer, this reduces the runtime from about 80 seconds to about 40 seconds. This test is not (yet) run regularly on CI, but when it was run recently, it timed out. PR-URL: #25522 Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 35240ca commit cfcb759

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

test/pummel/test-hash-seed.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22

33
// Check that spawn child doesn't create duplicated entries
44
require('../common');
5+
const Countdown = require('../common/countdown');
56
const REPETITIONS = 2;
67
const assert = require('assert');
78
const fixtures = require('../common/fixtures');
8-
const { spawnSync } = require('child_process');
9+
const { spawn } = require('child_process');
910
const targetScript = fixtures.path('guess-hash-seed.js');
1011
const seeds = [];
1112

13+
const requiredCallback = () => {
14+
console.log(`Seeds: ${seeds}`);
15+
assert.strictEqual(new Set(seeds).size, seeds.length);
16+
assert.strictEqual(seeds.length, REPETITIONS);
17+
};
18+
19+
const countdown = new Countdown(REPETITIONS, requiredCallback);
20+
1221
for (let i = 0; i < REPETITIONS; ++i) {
13-
const seed = spawnSync(process.execPath, [targetScript], {
14-
encoding: 'utf8'
15-
}).stdout.trim();
16-
seeds.push(seed);
17-
}
22+
let result = '';
23+
const subprocess = spawn(process.execPath, [targetScript]);
24+
subprocess.stdout.setEncoding('utf8');
25+
subprocess.stdout.on('data', (data) => { result += data; });
1826

19-
console.log(`Seeds: ${seeds}`);
20-
assert.strictEqual(new Set(seeds).size, seeds.length);
27+
subprocess.on('exit', () => {
28+
seeds.push(result.trim());
29+
countdown.dec();
30+
});
31+
}

0 commit comments

Comments
 (0)