Skip to content

Commit

Permalink
Tweak flakey on-demand revalidate test (#63953)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ijjk committed Apr 1, 2024
1 parent 2359d3d commit e0d4b4f
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions test/e2e/prerender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
hasRedbox,
normalizeRegEx,
renderViaHTTP,
retry,
waitFor,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand All @@ -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'
Expand All @@ -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')
})
})
}

Expand Down

0 comments on commit e0d4b4f

Please sign in to comment.