Fix two intermittently failing library tests (closes #90)
check / check (push) Successful in 15s
check / check (push) Successful in 15s
Library.close() now returns a promise that resolves once the work it started has finished: an in-flight refresh with its cache write, the ML data fetch, and running precache sweeps. The interval test could see a refresh's new state, close, and remove the directory while the write was still running. Every library test now awaits close(), and a new test holds a cache write open to prove close() waits for it. 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