Merge branch 'issue-177-ws-notify' into issue-178-sync-scheduler
This commit is contained in:
commit
f8ee31066c
2 changed files with 6 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ type FakeSocket = EventEmitter & {
|
|||
userId: string;
|
||||
readyState: number;
|
||||
send: ReturnType<typeof vi.fn>;
|
||||
terminate: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
const OPEN = 1; // WebSocket.OPEN
|
||||
|
|
@ -22,7 +23,7 @@ const g = globalThis as unknown as {
|
|||
};
|
||||
|
||||
function fakeSocket(userId: string): FakeSocket {
|
||||
return Object.assign(new EventEmitter(), { userId, readyState: OPEN, send: vi.fn() });
|
||||
return Object.assign(new EventEmitter(), { userId, readyState: OPEN, send: vi.fn(), terminate: vi.fn() });
|
||||
}
|
||||
|
||||
async function freshModule() {
|
||||
|
|
@ -106,6 +107,7 @@ describe('notifyUserChanged', () => {
|
|||
ws.notifyUserChanged('user-a');
|
||||
expect(() => vi.advanceTimersByTime(ws.NOTIFY_DEBOUNCE_MS)).not.toThrow();
|
||||
expect(ws.getActiveConnections()).toBe(0);
|
||||
expect(a.terminate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -171,7 +171,10 @@ export function broadcastToUser(userId: string, message: WsMessage) {
|
|||
try {
|
||||
ws.send(payload);
|
||||
} catch {
|
||||
// Close it too: left open, it would escape the heartbeat and the page
|
||||
// would never be notified again (its onclose reconnects it).
|
||||
clients.delete(ws);
|
||||
ws.terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue