Fix two intermittently failing library tests (closes #90)
check / check (push) Successful in 28s
check / check (push) Successful in 28s
Library.close() now returns a promise that resolves once an in-flight refresh, including its cache write, has finished. A refresh changes RAM before it writes the cache file, so the interval test could see the new state, close, and remove the directory while the write was still running. The library tests now await close(). The precache test waited for its stub source to be called, but the cache records a file only after checking it on disk, so status() could lag. It now waits for both fills to report "done". Model: opus-5-5
This commit is contained in:
@@ -402,35 +402,47 @@ describe("Precache through Library.open", () => {
|
||||
}
|
||||
|
||||
it("starts both precaches from open() and reports them in status()", async () => {
|
||||
const thumbFetched = new Set<number>();
|
||||
const origFetched = new Set<number>();
|
||||
const source: ContentSource = {
|
||||
original: async ({ file: f, destination }) => {
|
||||
origFetched.add(f.id);
|
||||
original: async ({ destination }) => {
|
||||
await writeFile(destination, Buffer.alloc(10, 1));
|
||||
return { bytesWritten: 10 };
|
||||
},
|
||||
thumbnail: async ({ file: f, destination }) => {
|
||||
thumbFetched.add(f.id);
|
||||
thumbnail: async ({ destination }) => {
|
||||
await writeFile(destination, Buffer.alloc(10, 1));
|
||||
return { bytesWritten: 10 };
|
||||
},
|
||||
};
|
||||
// Each fill reports "done" once the cache has recorded its files. The
|
||||
// source returning is not enough: the cache records a file only after
|
||||
// it has checked it on disk.
|
||||
const finished = new Set<string>();
|
||||
let bothFinished!: () => void;
|
||||
const precached = new Promise<void>((r) => (bothFinished = r));
|
||||
const lib = await Library.open({
|
||||
client: new MockClient(),
|
||||
cacheDirectory: join(root, "cache"),
|
||||
contentSource: source,
|
||||
refreshIntervalSeconds: 3600,
|
||||
onProgress: (e) => {
|
||||
if (
|
||||
e.status === "done" &&
|
||||
(e.operation === "precacheThumbnails" ||
|
||||
e.operation === "precacheOriginals")
|
||||
) {
|
||||
finished.add(e.operation);
|
||||
if (finished.size === 2) bothFinished();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// Every file's thumbnail is precached; the favorite (file 3) and the
|
||||
// week's files (1, 2) all have their originals precached.
|
||||
await until(() => thumbFetched.size === 3 && origFetched.size === 3);
|
||||
await precached;
|
||||
const status = lib.status();
|
||||
expect(status.thumbnailsTotal).toBe(3);
|
||||
expect(status.thumbnailsCached).toBe(3);
|
||||
expect(status.originalsPinned).toBe(3);
|
||||
expect(status.originalsCached).toBe(3);
|
||||
lib.close();
|
||||
await lib.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user