Fix LinkPreviewService test timeout and assertion failure

Wraps the `respects TTL` test body in a `try...finally` block to ensure `expiredService.db` is closed even if assertions fail, preventing `fake-indexeddb` from hanging during cleanup.
Adds a small delay to the same test to ensure time advances beyond the 0ms TTL (caused by negative TTL clamping), fixing a flaky assertion failure.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-01-27 18:36:32 +00:00
1 parent 8b9ef3858d
commit 415465d067
1 file changed
+13 -7
+13 -7
View File
@@ -95,16 +95,22 @@ test("LinkPreviewService", async (t) => {
await t.test("respects TTL", async () => {
// Set a preview that is expired
const expiredService = new LinkPreviewService({ ttlMs: -1000 });
// Initialize DB first to ensure we write to the same place
await expiredService.init();
try {
// Initialize DB first to ensure we write to the same place
await expiredService.init();
await expiredService.setCachedPreview("https://expired.com", { title: "Expired" });
await expiredService.setCachedPreview("https://expired.com", { title: "Expired" });
const cached = await expiredService.getCachedPreview("https://expired.com");
assert.equal(cached, null);
// Ensure time advances since TTL is clamped to 0
await new Promise((r) => setTimeout(r, 10));
if (expiredService.db) {
expiredService.db.close();
const cached = await expiredService.getCachedPreview("https://expired.com");
assert.equal(cached, null);
} finally {
if (expiredService.db) {
expiredService.db.close();
expiredService.db = null;
}
}
});