final uptime test + drop fix

This commit is contained in:
KingKDot
2026-03-10 20:37:32 -05:00
parent ecf5cd9c64
commit da4cbc4878
2 changed files with 34 additions and 4 deletions
+22
View File
@@ -69,4 +69,26 @@ describe("wsHandlers ping/pong", () => {
handlePong(info, { type: "pong", ts: 3333 } as any);
expect(info.lastPingNonce).toBe(2222);
});
test("handlePong clears matching nonce even when pong is late", () => {
metrics.reset();
const now = Date.now();
const info = {
id: "client-4",
role: "client",
ws: { sent: [], send() {} },
lastSeen: now - 60_000,
online: false,
lastPingSent: now - 20_000,
lastPingNonce: 4444,
} as any;
handlePong(info, { type: "pong", ts: 4444 } as any);
expect(info.lastPingNonce).toBeUndefined();
expect(info.online).toBe(true);
expect(info.lastSeen).toBeGreaterThan(now - 5_000);
const snapshot = metrics.getSnapshot();
expect(snapshot.ping.count).toBe(0);
});
});