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 { ...@@ -13,6 +13,7 @@ import {
hasRedbox, hasRedbox,
normalizeRegEx, normalizeRegEx,
renderViaHTTP, renderViaHTTP,
retry,
waitFor, waitFor,
} from 'next-test-utils' } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
...@@ -2132,18 +2133,11 @@ describe('Prerender', () => { ...@@ -2132,18 +2133,11 @@ describe('Prerender', () => {
if (!isDev) { if (!isDev) {
it('should handle on-demand revalidate for fallback: blocking', async () => { it('should handle on-demand revalidate for fallback: blocking', async () => {
const beforeRevalidate = Date.now()
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
next.url, next.url,
'/blocking-fallback/test-manual-1' '/blocking-fallback/test-manual-1'
) )
if (!isDeploy) {
await waitForCacheWrite(
'/blocking-fallback/test-manual-1',
beforeRevalidate
)
}
const html = await res.text() const html = await res.text()
const $ = cheerio.load(html) const $ = cheerio.load(html)
const initialTime = $('#time').text() const initialTime = $('#time').text()
...@@ -2153,15 +2147,19 @@ describe('Prerender', () => { ...@@ -2153,15 +2147,19 @@ describe('Prerender', () => {
expect($('p').text()).toMatch(/Post:.*?test-manual-1/) expect($('p').text()).toMatch(/Post:.*?test-manual-1/)
if (!isDeploy) { if (!isDeploy) {
const res2 = await fetchViaHTTP( // we use retry here as the cache might still be
next.url, // writing to disk even after the above request has finished
'/blocking-fallback/test-manual-1' await retry(async () => {
) const res2 = await fetchViaHTTP(
const html2 = await res2.text() next.url,
const $2 = cheerio.load(html2) '/blocking-fallback/test-manual-1'
)
const html2 = await res2.text()
const $2 = cheerio.load(html2)
expect(res2.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/) expect(res2.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/)
expect(initialTime).toBe($2('#time').text()) expect(initialTime).toBe($2('#time').text())
})
} }
const res3 = await fetchViaHTTP( const res3 = await fetchViaHTTP(
...@@ -2177,7 +2175,7 @@ describe('Prerender', () => { ...@@ -2177,7 +2175,7 @@ describe('Prerender', () => {
const revalidateData = await res3.json() const revalidateData = await res3.json()
expect(revalidateData.revalidated).toBe(true) expect(revalidateData.revalidated).toBe(true)
await check(async () => { await retry(async () => {
const res4 = await fetchViaHTTP( const res4 = await fetchViaHTTP(
next.url, next.url,
'/blocking-fallback/test-manual-1' '/blocking-fallback/test-manual-1'
...@@ -2186,8 +2184,7 @@ describe('Prerender', () => { ...@@ -2186,8 +2184,7 @@ describe('Prerender', () => {
const $4 = cheerio.load(html4) const $4 = cheerio.load(html4)
expect($4('#time').text()).not.toBe(initialTime) expect($4('#time').text()).not.toBe(initialTime)
expect(res4.headers.get(cacheHeader)).toMatch(/(HIT|STALE)/) 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