Skip to content

Commit 3e9d992

Browse files
TrottMylesBorins
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 <ofrobots@google.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
1 parent 1592ebd commit 3e9d992

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Diff for: 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)