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
+43 -37
View File
@@ -446,47 +446,53 @@ 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",
let release!: () => void; async (kind) => {
const held = new Promise<void>((r) => (release = r)); // Only the fill under test runs, and each of its fetches waits
let fetchStarted!: (destination: string) => void; // until the test releases it.
const started = new Promise<string>((r) => (fetchStarted = r)); let release!: () => void;
const source: ContentSource = { const held = new Promise<void>((r) => (release = r));
original: async ({ destination }) => { let fetchStarted!: (destination: string) => void;
await writeFile(destination, Buffer.alloc(10, 1)); const started = new Promise<string>((r) => (fetchStarted = r));
return { bytesWritten: 10 }; const fetch = async ({ destination }: { destination: string }) => {
},
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 () => {
const lib = await Library.open({ throw new Error("this fill is turned off");
client: new MockClient(), };
cacheDirectory: join(root, "cache"), const source: ContentSource =
contentSource: source, kind === "thumbnail"
refreshIntervalSeconds: 3600, ? { original: unused, thumbnail: fetch }
precacheOriginals: false, : { original: fetch, thumbnail: unused };
}); const lib = await Library.open({
try { client: new MockClient(),
const destination = await started; cacheDirectory: join(root, "cache"),
contentSource: source,
let closed = false; refreshIntervalSeconds: 3600,
const closing = lib.close().then(() => { precacheThumbnails: kind === "thumbnail",
closed = true; precacheOriginals: kind === "original",
}); });
await new Promise((r) => setTimeout(r, 20)); try {
expect(closed).toBe(false); const destination = await started;
release(); let closed = false;
await closing; const closing = lib.close().then(() => {
expect(existsSync(destination)).toBe(true); closed = true;
} finally { });
release(); await new Promise((r) => setTimeout(r, 20));
await lib.close(); expect(closed).toBe(false);
}
}); release();
await closing;
expect(existsSync(destination)).toBe(true);
} finally {
release();
await lib.close();
}
},
);
}); });