Skip to content

Commit 5c7e6b4

Browse files
panvaaduh95
authored andcommitted
test: synchronize ordered runner events
Release the slow fixture over a local socket after the fast fixture emits its bypassed completion event. This removes the fixed 30-second delay while preserving event-order assertions and a bounded failure timeout. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #65980 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
1 parent 37f24ed commit 5c7e6b4

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { test } from 'node:test';
2-
import { setTimeout as sleep } from 'node:timers/promises';
2+
import { once } from 'node:events';
3+
import { connect } from 'node:net';
34

45
test('slow', async () => {
5-
// Long enough that fast-fail's process can spawn, run, and round-trip its
6-
// bypassed test:complete to the host on slow CI, but short enough that the
7-
// test does not waste much time when the bypass is working.
8-
await sleep(30_000);
6+
// The host closes this connection after receiving fast-fail's bypassed
7+
// test:complete event, so this test cannot finish before that event arrives.
8+
const socket = connect(Number(process.argv[2]), '127.0.0.1');
9+
socket.resume();
10+
await once(socket, 'end');
911
});

test/parallel/test-runner-execution-ordered-bypass.mjs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
// Flags: --no-warnings
22

3-
import '../common/index.mjs';
3+
import { mustCall, platformTimeout } from '../common/index.mjs';
44
import * as fixtures from '../common/fixtures.mjs';
55
import assert from 'node:assert';
6+
import { once } from 'node:events';
7+
import { createServer } from 'node:net';
68
import { test, run } from 'node:test';
79

810
const files = [
911
fixtures.path('test-runner', 'execution-ordered-bypass', 'slow.mjs'),
1012
fixtures.path('test-runner', 'execution-ordered-bypass', 'fast-fail.mjs'),
1113
];
1214

13-
test('execution-ordered events bypass FileTest declaration-order buffer', async () => {
15+
test('execution-ordered events bypass FileTest declaration-order buffer', {
16+
timeout: platformTimeout(30_000),
17+
}, async (t) => {
18+
const { promise: fastCompleted, resolve: releaseSlow } = Promise.withResolvers();
19+
const server = createServer(mustCall((socket) => {
20+
t.after(() => socket.destroy());
21+
fastCompleted.then(mustCall(() => {
22+
socket.end();
23+
}));
24+
}));
25+
t.after(() => server.close());
26+
await once(server.listen(0, '127.0.0.1'), 'listening');
27+
1428
// Concurrency must be a number so the runner does not collapse it to 1 on
1529
// single-core CI runners (where `concurrency: true` resolves to
1630
// `availableParallelism() - 1`). Without two slots the runner spawns the
17-
// files sequentially and fast-fail never starts while slow is sleeping.
31+
// files sequentially and fast-fail never starts while slow is waiting.
1832
const stream = run({
1933
files,
2034
isolation: 'process',
2135
concurrency: 2,
36+
argv: [String(server.address().port)],
37+
signal: t.signal,
2238
});
2339

2440
const events = [];
@@ -27,6 +43,9 @@ test('execution-ordered events bypass FileTest declaration-order buffer', async
2743
if (data.name === 'slow' || data.name === 'fast-fail') {
2844
events.push(`complete:${data.name}`);
2945
}
46+
if (data.name === 'fast-fail') {
47+
releaseSlow();
48+
}
3049
});
3150

3251
stream.on('test:fail', (data) => {

0 commit comments

Comments
 (0)