huge optimizations

This commit is contained in:
KingKDot
2026-06-08 22:33:34 -05:00
parent 9a1fc96e2b
commit d6ad2cadea
21 changed files with 649 additions and 72 deletions
+24 -1
View File
@@ -1,7 +1,7 @@
import { describe, expect, test } from "bun:test";
import { decodeMessage } from "./protocol";
import { metrics } from "./metrics";
import { handlePong, sendPingRequest } from "./wsHandlers";
import { handlePing, handlePong, sendPingRequest } from "./wsHandlers";
type MockWs = { sent: Uint8Array[]; send: (msg: Uint8Array) => void };
@@ -30,6 +30,29 @@ describe("wsHandlers ping/pong", () => {
expect(ws.sent.length).toBe(1);
});
test("handlePing responds with pong without starting another server ping", () => {
const ws: MockWs = {
sent: [],
send(msg) {
this.sent.push(msg);
},
};
const info = {
id: "client-ping",
role: "client",
ws,
lastSeen: Date.now(),
} as any;
handlePing(info, { type: "ping", ts: 9876 } as any, ws);
expect(ws.sent.length).toBe(1);
const payload = decodeMessage(ws.sent[0]) as any;
expect(payload.type).toBe("pong");
expect(payload.ts).toBe(9876);
expect(info.lastPingNonce).toBeUndefined();
});
test("handlePong clears nonce and records ping", () => {
metrics.reset();
const ws: MockWs = {