From ffe5556ec37244c0758e5d4d85ab89353e6503f7 Mon Sep 17 00:00:00 2001 From: le king fu Date: Sat, 7 Nov 2026 21:46:41 -0500 Subject: [PATCH] test(sync): pin the canSync check after the ticket and the timer cleanup on stop (#175) Refs #175 Co-Authored-By: Claude Opus 5.5 --- tests/syncSocket.test.mjs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/syncSocket.test.mjs b/tests/syncSocket.test.mjs index 93060ed..9db3000 100644 --- a/tests/syncSocket.test.mjs +++ b/tests/syncSocket.test.mjs @@ -380,10 +380,38 @@ test('stop during a reconnection wait cancels it', async () => { await flush(); assert.equal(h.socket.state(), 'waiting'); h.socket.stop(); + // The reconnection timer is cleared, not just ignored when it fires + assert.equal(h.clock.pending(), 0); await h.clock.advance(600_000); assert.equal(h.ticketTimes.length, 1); }); +test('canSync false while the ticket is in flight, without check: no socket opens', async () => { + let release; + const h = harness(); + let allowed = true; + const s = createSyncSocket({ + now: h.clock.now, setTimer: h.clock.setTimer, clearTimer: h.clock.clearTimer, random: () => 0.5, + canOpen: () => allowed, + requestTicket: () => new Promise((resolve) => (release = resolve)), + // Recorded, not thrown: a throw would be caught as a failed connection + connect: () => { + connects++; + return { close() {} }; + }, + sync: () => {}, + }); + let connects = 0; + s.start(); + await flush(); + allowed = false; + release({ kind: 'ok', ticket: 't' }); + await flush(); + assert.equal(connects, 0); + assert.equal(s.state(), 'closed'); + assert.equal(h.clock.pending(), 0); +}); + test('stop while the ticket is in flight: no socket opens', async () => { let release; const h = harness();