From e0d4b4f414e9670940f831ea821496fa601b219a Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 1 Apr 2024 15:00:40 -0700 Subject: [PATCH] Tweak flakey on-demand revalidate test (#63953) This test flakes due to cache writing race so this uses retry instead to avoid this. x-ref: https://github.com/vercel/next.js/actions/runs/8512132584/job/23313143810?pr=63921 Closes NEXT-2974 --- test/e2e/prerender.test.ts | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/test/e2e/prerender.test.ts b/test/e2e/prerender.test.ts index cf5bcca77d83a..5b6fb5f72c544 100644 --- a/test/e2e/prerender.test.ts +++ b/test/e2e/prerender.test.ts @@ -13,6 +13,7 @@ import { hasRedbox, normalizeRegEx, renderViaHTTP, + retry, waitFor, } from 'next-test-utils' import webdriver from 'next-webdriver' @@ -2132,18 +2133,11 @@ describe('Prerender', () => { if (!isDev) { it('should handle on-demand revalidate for fallback: blocking', async () => { - const beforeRevalidate = Date.now() const res = await fetchViaHTTP( next.url, '/blocking-fallback/test-manual-1' ) - if (!isDeploy) { - await waitForCacheWrite( - '/blocking-fallback/test-manual-1', - beforeRevalidate - ) - } const html = await res.text() const $ = cheerio.load(html) const initialTime = $('#time').text() @@ -2153,15 +2147,19 @@ describe('Prerender', () => { expect($('p').text()).toMatch(/Post:.*?test-manual-1/) if (!isDeploy) { - const res2 = await fetchViaHTTP( - next.url, - '/blocking-fallback/test-manual-1' - ) - const html2 = await res2.text() - const $2 = cheerio.load(html2) + // we use retry here as the cache might still be + // writing to disk even after the above request has finished + await retry(async () => { + const res2 = await fetchViaHTTP( + next.url, + '/blocking-fallback/test-manual-1' + ) + const html2 = await res2.text() + const $2 = cheerio.load(html2) - expect(res2.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/) - expect(initialTime).toBe($2('#time').text()) + expect(res2.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/) + expect(initialTime).toBe($2('#time').text()) + }) } const res3 = await fetchViaHTTP( @@ -2177,7 +2175,7 @@ describe('Prerender', () => { const revalidateData = await res3.json() expect(revalidateData.revalidated).toBe(true) - await check(async () => { + await retry(async () => { const res4 = await fetchViaHTTP( next.url, '/blocking-fallback/test-manual-1' @@ -2186,8 +2184,7 @@ describe('Prerender', () => { const $4 = cheerio.load(html4) expect($4('#time').text()).not.toBe(initialTime) expect(res4.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/) - return 'success' - }, 'success') + }) }) }