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 <noreply@anthropic.com>
This commit is contained in:
parent
a729da04e7
commit
dc72231831
1 changed files with 28 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue