Files
OmniRoute/tests/unit/proxy-dispatcher-cache-cap.test.ts
Paijo 6c0437f136 fix(proxy): restore connection pooling on proxy/relay paths (#9100) (#9158)
Validated in local merge-train (devbox-vm-06-dev002) @ combined-tip (FAST gates green: static + changed tests + vitest — only pre-existing audit.test.ts flake). Evidence: /home/diegosouzapw/dev/proxys/OmniRoute/.claude/worktrees/merge-train-20260805-213228-suite.log
2026-08-05 21:43:55 -03:00

32 lines
989 B
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
setDispatcherCacheEntry,
getDispatcherCache,
clearDispatcherCache,
} from "../../open-sse/utils/proxyDispatcherCache.ts";
describe("proxy dispatcher cache cap (#9158)", () => {
it("evicts and closes the oldest entry at the 512-entry cap", () => {
let closedCount = 0;
const fakeDispatcher = {
close() {
closedCount += 1;
return Promise.resolve();
},
} as never;
for (let i = 0; i <= 512; i += 1) {
setDispatcherCacheEntry(`u${i}`, fakeDispatcher);
}
assert.equal(getDispatcherCache().size, 512, "cache must stay at the cap");
assert.equal(closedCount, 1, "exactly one entry must be evicted and closed");
assert.equal(getDispatcherCache().has("u0"), false, "oldest entry must be evicted");
assert.equal(getDispatcherCache().has("u512"), true, "newest entry must be retained");
clearDispatcherCache();
});
});