fix: refcount StatsCache keys, keep registrations across config change, and tidy GPU/usage render paths
This commit is contained in:
@@ -83,3 +83,26 @@ test("fetch failure keeps the last-known value", async () => {
|
||||
assert.equal(cache.get("a"), undefined);
|
||||
cache.unregister("a");
|
||||
});
|
||||
|
||||
test("ref-counted register: a sibling unregister keeps the key active", async () => {
|
||||
const calls = { count: 0 };
|
||||
const cache = new StatsCache(cfg, stubFetch({ totalRequests: 5, totalInputTokens: 1, totalOutputTokens: 1, genP95: 1 }, calls), 10000, 30);
|
||||
cache.register("all");
|
||||
cache.register("all");
|
||||
cache.unregister("all");
|
||||
await flush();
|
||||
assert.equal(cache.get("all")!.totalRequests, 5);
|
||||
assert.equal(calls.count, 1);
|
||||
cache.unregister("all");
|
||||
assert.equal(cache.get("all"), undefined);
|
||||
});
|
||||
|
||||
test("setConfig keeps registrations but clears cached values", async () => {
|
||||
const cache = new StatsCache(cfg, async (_c, key) => ({ totalRequests: 5, totalInputTokens: 1, totalOutputTokens: 1, genP95: 1 }), 10000, 30);
|
||||
cache.register("all");
|
||||
await flush();
|
||||
assert.equal(cache.get("all")!.totalRequests, 5);
|
||||
cache.setConfig({ baseUrl: "http://new" });
|
||||
assert.equal(cache.get("all"), undefined);
|
||||
cache.unregister("all");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user