Files
captoys/diigo-cache/tests/test-worker.ts
T
dckc fd16c7db53 diigo-cache: pace diigo calls only; cache hits don't wait
page() ran the 500 ms pacing gate before the cache check, so every hit
waited too: a fill rerun skipping 166 cached pages took ~80 s and
looked like a start from scratch. The gate now sits after the hit
check (re-checking storage once through it, in case a request ahead
had just etched the page).

Regression test: the fixed-clock test cache records its sleeps; a miss
sleeps once, three hits add none (failed before: 4 sleeps).

Generated-by: Claude Opus 5.5
2026-10-07 05:06:17 -05:00

35 lines
948 B
TypeScript

/**
* @file the tests' main module — their edge: the real worker (whose own
* edge supplies the live clock), plus the private cache's logic on a fixed
* clock (bound as CLOCKED_DO in wrangler.tests.jsonc).
*/
import { DiigoCacheLogic } from "../src/cache.js";
import type { CacheEnv } from "../src/cache.js";
export * from "../src/index.js";
export { default } from "../src/index.js";
/** 2026-10-07T12:00:00Z */
export const FIXED_NOW = Date.UTC(2026, 9, 7, 12, 0, 0);
/** a fixed clock that records each sleep it is asked for */
export class FixedClockCache extends DiigoCacheLogic {
#sleeps: number[] = [];
constructor(ctx: DurableObjectState, env: CacheEnv) {
const sleeps: number[] = [];
super(ctx, env, {
now: () => FIXED_NOW,
sleep: async (ms) => {
sleeps.push(ms);
},
});
this.#sleeps = sleeps;
}
/** the sleeps so far (test hook) */
async sleeps(): Promise<number[]> {
return [...this.#sleeps];
}
}