Skip to content

Commit a5e2fd9

Browse files
committed
test(sync): wait for SIGINT listener registration in listener-baseline test
Same flake class as the SIGHUP fix — "returns SIGINT/SIGTERM listener counts to their baseline after shutdown" (line 943) surfaced on Node 22 CI once the earlier SIGHUP flake was fixed. Under worker contention the fixed-50 flushWatchSetup() rounds occasionally return before watchAndSync reaches its process.on('SIGINT', ...) call, producing "Expected: 1, Received: 0" at the listenerCount assertion. Apply the same bounded wait-until-registered loop in both halves of the test (firstRun and secondRun) so failures remain loud but timing-robust.
1 parent e6c77c8 commit a5e2fd9

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

tests/unit/sync/sync-command.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,13 @@ describe('SyncCommand', () => {
953953
// signal to the real process emitter (listeners only react synchronously).
954954
const firstRun = command.run({ watch: true, debounce: 50 } as CliSyncOptions);
955955
await flushWatchSetup();
956+
// Under heavy CI worker contention the fixed-round flush occasionally
957+
// returns before watchAndSync has reached its process.on('SIGINT', ...)
958+
// call. Loop with a hard ceiling so we fail loudly rather than with a
959+
// misleading "Expected: 1, Received: 0".
960+
for (let i = 0; i < 10 && process.listenerCount('SIGINT') === sigintBaseline; i++) {
961+
await flushWatchSetup();
962+
}
956963
expect(process.listenerCount('SIGINT')).toBe(sigintBaseline + 1);
957964
expect(process.listenerCount('SIGTERM')).toBe(sigtermBaseline + 1);
958965

@@ -965,6 +972,9 @@ describe('SyncCommand', () => {
965972
// Second invocation should also add exactly one listener, then remove it.
966973
const secondRun = command.run({ watch: true, debounce: 50 } as CliSyncOptions);
967974
await flushWatchSetup();
975+
for (let i = 0; i < 10 && process.listenerCount('SIGINT') === sigintBaseline; i++) {
976+
await flushWatchSetup();
977+
}
968978
expect(process.listenerCount('SIGINT')).toBe(sigintBaseline + 1);
969979
expect(process.listenerCount('SIGTERM')).toBe(sigtermBaseline + 1);
970980

0 commit comments

Comments
 (0)