fix: recover the websocket when a close goes unreported

This commit is contained in:
Carlos Valente
2026-09-15 18:20:35 +02:00
committed by Carlos Valente
parent 2436ec2f9a
commit 4c656950f0
2 changed files with 29 additions and 7 deletions
@@ -40,6 +40,10 @@ class MockWebSocket {
this.onclose?.();
}
/** Simulates a lost connection without an onclose event. */
closeSilently() {
this.readyState = MockWebSocket.CLOSED;
}
open() {
this.readyState = MockWebSocket.OPEN;
this.onopen?.();
@@ -146,6 +150,16 @@ describe('socket connection watchdog', () => {
expect(MockWebSocket.instances).toHaveLength(2);
});
it('recovers when a close goes unreported', () => {
const socket = openConnection();
// The watchdog is the only recovery path when no close event arrives.
socket.closeSilently();
vi.advanceTimersByTime(watchdogInterval + socketConfig.reconnectBaseInterval * 2);
expect(MockWebSocket.instances).toHaveLength(2);
});
it('ignores events from a socket which has been replaced', () => {
const stale = openConnection();