diigo-cache: the caches take their clock as a constructor argument
Ocap discipline: no ambient time in logic. PagedCache reads time and
waits only through a Clock { now, sleep }, a default constructor
argument (the live clock; the runtime constructs DOs with ctx and env
only). The fill job's timestamps and alarms, the etch time, and the
diigo-call pacing all go through it.
Tests interpose through the constructor: tests/test-worker.ts (now the
tests' main module) adds FixedClockCache, bound as CLOCKED_DO, and a
test pins startedAt, updatedAt, and the alarm time to the fixed clock
(an ambient new Date() fails it).
Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
7d2100bf77
commit
b6823867ff
4 files changed
+76
-17
No files matched your search
@@ -5,6 +5,7 @@ import worker from "../src/index.js";
|
||||
import { newHttpBatchRpcSession } from "capnweb";
|
||||
import type { CacheApi } from "../src/api.js";
|
||||
import { toWebkey } from "../src/webkeys.js";
|
||||
import { FIXED_NOW } from "./test-worker.js";
|
||||
|
||||
// goal 1e (capsite checklist): a job that grabs every page. Fake
|
||||
// accounts: tests/fake-webapp.js ("fake-webapp-id": 30 items = 2 pages
|
||||
@@ -12,6 +13,7 @@ import { toWebkey } from "../src/webkeys.js";
|
||||
|
||||
type TestEnv = {
|
||||
CACHE_DO: DurableObjectNamespace<import("../src/cache.js").DiigoCache>;
|
||||
CLOCKED_DO: DurableObjectNamespace<import("./test-worker.js").FixedClockCache>;
|
||||
PUBLIC_DO: DurableObjectNamespace<import("../src/cache.js").PublicCache>;
|
||||
WEBAPP: { calls(): Promise<number> };
|
||||
};
|
||||
@@ -107,6 +109,18 @@ describe("fill job (goal 1e)", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("reads time only through its clock: a fixed clock pins the timestamps and the alarm", async () => {
|
||||
const stub = testEnv.CLOCKED_DO.get(testEnv.CLOCKED_DO.newUniqueId());
|
||||
await stub.setup({ webappId: "fake-webapp-id" });
|
||||
const at = new Date(FIXED_NOW).toISOString();
|
||||
expect(await stub.startFill()).toMatchObject({ startedAt: at, updatedAt: at });
|
||||
await runInDurableObject(stub, async (_obj, state) => {
|
||||
expect(await state.storage.getAlarm()).toBe(FIXED_NOW + 1000);
|
||||
});
|
||||
await drain(stub);
|
||||
expect(await stub.fillStatus()).toMatchObject({ state: "done", updatedAt: at });
|
||||
});
|
||||
|
||||
it("a public cache's fill stores no private rows", async () => {
|
||||
const stub = testEnv.PUBLIC_DO.get(testEnv.PUBLIC_DO.newUniqueId());
|
||||
await stub.setup({ webappId: "fake-webapp-id" });
|
||||
|
||||
Reference in new issue
Block a user