Unverified Commit e0d4b4f4 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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
parent 2359d3d2
......@@ -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')
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment