Test that close() waits for the originals precache (closes #93) #94
@@ -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
@@ -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();
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
新增問題並參考
封鎖使用者