test(binary): drain AwaitingInitialSync timer & fix stale comment
Addresses 2 review comments on PR #384: - Codex P2: the fresh-pair test ended the socket immediately after the buffer assertion, leaving the 2s setTimeout in chats.ts:1522 alive. Its callback fired post-teardown and emitted "Cannot log after tests are done" via baileys-logger, making the suite noisy and trippable by --detectOpenHandles. Drain the timer with a 2.1s wait before cleanup; bump the per-test timeout to 10s to accommodate it. - Copilot: the file header said "live messages are not held for up to 4 seconds", but the chats.ts AwaitingInitialSync timeout is 2s. Replace the stale literal with "the initial-sync window" so the comment doesn't drift again when the timeout is tuned. Skipped intentionally (per PR review): - CodeRabbit Major (try/finally cleanup): diverges from the pattern used by the only sibling test (connection-deadlock.test.ts). - CodeRabbit Nitpick (replace 50ms sleeps with deterministic waits): not flaky in practice; sibling test uses the same pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ mockWebSocket()
|
||||
// (socket.ts already decided to skip the offline buffer, e.g. because
|
||||
// routingInfo was stale and was discarded on startup)
|
||||
// On reconnection, AwaitingInitialSync is skipped and the buffer is flushed
|
||||
// immediately so live messages are not held for up to 4 seconds.
|
||||
// immediately so live messages are not held in the initial-sync window.
|
||||
describe('Reconnection Sync Skip', () => {
|
||||
it('should skip the history sync wait on reconnection (accountSyncCounter > 0)', async () => {
|
||||
const { state, clear } = await makeSession()
|
||||
@@ -132,7 +132,15 @@ describe('Reconnection Sync Skip', () => {
|
||||
// Message should be BUFFERED (not delivered) because we're waiting for history sync
|
||||
expect(messageListener).toHaveBeenCalledTimes(0)
|
||||
|
||||
// Drain the 2s AwaitingInitialSync timeout (chats.ts:1522) so its callback
|
||||
// doesn't fire after Jest considers the test done — otherwise we get a
|
||||
// "Cannot log after tests are done" warning from the post-teardown flush
|
||||
// and the suite is flagged with --detectOpenHandles. After the timer
|
||||
// fires, syncState becomes Online and the buffer flushes; that delivery
|
||||
// is post-assertion and irrelevant to the test goal.
|
||||
await new Promise(resolve => setTimeout(resolve, 2_100))
|
||||
|
||||
await sock.end(new Error('Test completed'))
|
||||
await clear()
|
||||
})
|
||||
}, 10_000)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user