Skip to content

Commit e6c77c8

Browse files
committed
test(sync): wait for watcher handlers to register in SIGHUP cache test
"reloads sync config when SIGHUP is received" flaked on the Node 22 CI job with TypeError: handlers[0] is not a function, because the fixed-50 rounds of flushWatchSetup() occasionally return before chokidar's dynamic-import + FS-sweep chain reaches watcher.on('change', ...). Add a bounded wait-until-registered loop (max 10 extra flushes) and a length assertion so the test either succeeds or fails loudly with a clear diagnostic, instead of the misleading TypeError. The sibling "three ticks" test at line 1027 already has an implicit barrier (expect(handlers.length).toBeGreaterThan(0)) which is why it has not flaked.
1 parent 117d576 commit e6c77c8

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,14 @@ describe('SyncCommand', () => {
10761076

10771077
const runPromise = command.run({ watch: true, debounce: 50 } as CliSyncOptions);
10781078
await flushWatchSetup();
1079+
// Under CI worker contention the fixed-round flush occasionally
1080+
// returns before watcher.on('change', ...) has registered. Loop
1081+
// flushWatchSetup with a hard ceiling so we fail loudly rather than
1082+
// with the misleading "handlers[0] is not a function".
1083+
for (let i = 0; i < 10 && handlers.length === 0; i++) {
1084+
await flushWatchSetup();
1085+
}
1086+
expect(handlers.length).toBeGreaterThan(0);
10791087

10801088
const initialLoads = mockLoadSyncConfig.mock.calls.length;
10811089

0 commit comments

Comments
 (0)