Test that close() waits for the originals precache (closes #93) #94

Merged
clawbot merged 1 commits from issue-93-originals-close-test into next2 2026-09-23 04:54:46 +02:00
2 changed files with 47 additions and 37 deletions
Showing only changes of commit 11fcad12b9 - Show all commits
+4
View File
@@ -18,6 +18,10 @@ Tag v1.0.0.
# Completed Steps # Completed Steps
- 2026-09-23: Tested that `Library.close()` waits for the originals precache
(issue 93). The test that holds a precache fetch open while `close()` runs now
runs once with only the thumbnail fill and once with only the originals fill,
so dropping either wait from `Precache.close()` fails a test.
- 2026-09-23: Fixed two intermittently failing library tests (issue 90). - 2026-09-23: Fixed two intermittently failing library tests (issue 90).
`Library.close()` now returns a promise that resolves once an in-flight `Library.close()` now returns a promise that resolves once an in-flight
refresh (including its cache write), the ML data fetch and running precache refresh (including its cache write), the ML data fetch and running precache
+17 -11
View File
@@ -446,30 +446,35 @@ describe("Precache through Library.open", () => {
await lib.close(); await lib.close();
}); });
it("close() resolves only after a running precache fetch has written its file", async () => { it.each(["thumbnail", "original"] as const)(
// Every thumbnail fetch waits until the test releases it. "close() resolves only after a running %s precache fetch has written its file",
async (kind) => {
// Only the fill under test runs, and each of its fetches waits
// until the test releases it.
let release!: () => void; let release!: () => void;
const held = new Promise<void>((r) => (release = r)); const held = new Promise<void>((r) => (release = r));
let fetchStarted!: (destination: string) => void; let fetchStarted!: (destination: string) => void;
const started = new Promise<string>((r) => (fetchStarted = r)); const started = new Promise<string>((r) => (fetchStarted = r));
const source: ContentSource = { const fetch = async ({ destination }: { destination: string }) => {
original: async ({ destination }) => {
await writeFile(destination, Buffer.alloc(10, 1));
return { bytesWritten: 10 };
},
thumbnail: async ({ destination }) => {
fetchStarted(destination); fetchStarted(destination);
await held; await held;
await writeFile(destination, Buffer.alloc(10, 1)); await writeFile(destination, Buffer.alloc(10, 1));
return { bytesWritten: 10 }; return { bytesWritten: 10 };
},
}; };
const unused = async () => {
throw new Error("this fill is turned off");
};
const source: ContentSource =
kind === "thumbnail"
? { original: unused, thumbnail: fetch }
: { original: fetch, thumbnail: unused };
const lib = await Library.open({ const lib = await Library.open({
client: new MockClient(), client: new MockClient(),
cacheDirectory: join(root, "cache"), cacheDirectory: join(root, "cache"),
contentSource: source, contentSource: source,
refreshIntervalSeconds: 3600, refreshIntervalSeconds: 3600,
precacheOriginals: false, precacheThumbnails: kind === "thumbnail",
precacheOriginals: kind === "original",
}); });
try { try {
const destination = await started; const destination = await started;
@@ -488,5 +493,6 @@ describe("Precache through Library.open", () => {
release(); release();
await lib.close(); await lib.close();
} }
}); },
);
}); });