From 6ec78d2ec49e6c8eb79c0f418f31dcb4b78dc3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 7 Aug 2026 12:12:51 +0200 Subject: [PATCH] test: wait for the cached entry the disk-layer control asserts The service worker writes its data-cache entry after the response has been handed to the page, so a shell that is ready is not evidence that the write has landed. Reading the cache once therefore sampled null on a loaded machine, and the positive control failed saying there was no entry about a cache that was about to have one. Polled on the entry itself. It waits for the signal rather than for a number of milliseconds, and it still fails if the entry never appears, which is the whole reason the control is there. --- e2e/v137-record-session-fence-offline.spec.ts | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/e2e/v137-record-session-fence-offline.spec.ts b/e2e/v137-record-session-fence-offline.spec.ts index be33e606b..d2e281d6e 100644 --- a/e2e/v137-record-session-fence-offline.spec.ts +++ b/e2e/v137-record-session-fence-offline.spec.ts @@ -370,28 +370,43 @@ test.describe.serial("FENCE-AC-07 record-fence disk layers", () => { await expectShellReady(page); // The context those bytes were stored under, read off the entry itself. - const stored = await page.evaluate(async () => { - for (const name of (await caches.keys()).filter((n) => - n.startsWith("healthlog-data-"), - )) { - const cache = await caches.open(name); - for (const request of await cache.keys()) { - if (!new URL(request.url).pathname.startsWith("/api/measurements")) - continue; - const response = await cache.match(request); - if (!response) continue; - return { - cacheName: name, - url: request.url, - vary: response.headers.get("Vary"), - epoch: response.headers.get("x-healthlog-record-epoch"), - scope: response.headers.get("x-healthlog-record-scope"), - }; + // + // Polled, not sampled once. The service worker writes its `healthlog-data-*` + // entry AFTER the response has been handed to the page, so + // `expectShellReady` returning is not evidence that the write has landed — + // it is evidence that the read arrived. Sampling here read `null` on a + // loaded machine and failed the positive control below, which then said + // "there is no cache entry" about a cache that was about to have one. + // Waiting on the entry itself waits for the signal rather than for a + // number of milliseconds, and it still fails if the entry never appears. + const readStoredEntry = async () => + page.evaluate(async () => { + for (const name of (await caches.keys()).filter((n) => + n.startsWith("healthlog-data-"), + )) { + const cache = await caches.open(name); + for (const request of await cache.keys()) { + if ( + !new URL(request.url).pathname.startsWith("/api/measurements") + ) + continue; + const response = await cache.match(request); + if (!response) continue; + return { + cacheName: name, + url: request.url, + vary: response.headers.get("Vary"), + epoch: response.headers.get("x-healthlog-record-epoch"), + scope: response.headers.get("x-healthlog-record-scope"), + }; + } } - } - return null; - }); + return null; + }); + // POSITIVE CONTROL: there really is an entry, stored with a context. + await expect.poll(readStoredEntry, { timeout: 20_000 }).not.toBeNull(); + const stored = await readStoredEntry(); expect(stored).not.toBeNull(); expect(stored!.epoch).toMatch(/^\d+$/); expect(stored!.scope).not.toBe("self");