test: strengthen refcount and setConfig regression coverage
This commit is contained in:
@@ -88,11 +88,12 @@ 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");
|
||||
await flush();
|
||||
assert.equal(cache.get("all")!.totalRequests, 5);
|
||||
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);
|
||||
});
|
||||
@@ -104,5 +105,9 @@ test("setConfig keeps registrations but clears cached values", async () => {
|
||||
assert.equal(cache.get("all")!.totalRequests, 5);
|
||||
cache.setConfig({ baseUrl: "http://new" });
|
||||
assert.equal(cache.get("all"), undefined);
|
||||
cache.scheduleRefresh();
|
||||
await flush();
|
||||
await new Promise((r) => setTimeout(r, 60));
|
||||
assert.equal(cache.get("all")!.totalRequests, 5);
|
||||
cache.unregister("all");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user