Unverified Commit c18acf5c authored by Josh Story's avatar Josh Story Committed by GitHub

test: deflake use-cache-size-zero warm reload (#97421)

## Summary

Keep the first warm reload assertion focused on browser-visible
stale-while-revalidate behavior, then poll the route with independent
HTTP requests until a later response observes the fresh value. After
convergence, perform one final browser reload to confirm the
user-visible path also receives an updated value.

This avoids fixed delays, cache debug logging, and repeated browser
navigations that can cancel or outpace background regeneration. The
convergence poll uses the standard 3-second `retry()` window and returns
as soon as freshness is observed; the browser only reloads again after
that condition is satisfied.

## Verification

- `__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true NEXT_TEST_CI=true
HEADLESS=true pnpm test-dev-webpack
test/development/app-dir/use-cache-size-zero/use-cache-size-zero.test.ts`
- `__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true NEXT_TEST_CI=true
HEADLESS=true pnpm test-dev-turbo
test/development/app-dir/use-cache-size-zero/use-cache-size-zero.test.ts`

<!-- NEXT_JS_LLM -->
parent dd76599c
...@@ -24,14 +24,12 @@ describe('use-cache-size-zero', () => { ...@@ -24,14 +24,12 @@ describe('use-cache-size-zero', () => {
expect(await browser.elementByCss('p', { waitUntil: false }).text()).toBe( expect(await browser.elementByCss('p', { waitUntil: false }).text()).toBe(
'Loading...' 'Loading...'
) )
await retry(async () => { // After observing the streamed fallback, wait for the initial document to
expect( // finish loading so the cold request is fully settled before reloading.
await browser.elementByCss('p', { waitUntil: false }).text()
).toBeDateString()
})
const coldValue = await browser const coldValue = await browser
.elementByCss('p', { waitUntil: false }) .elementByCss('#value', { waitUntil: 'load' })
.text() .text()
expect(coldValue).toBeDateString()
// Warm reload: `cacheMaxMemorySize: 0` still caches in development, so the // Warm reload: `cacheMaxMemorySize: 0` still caches in development, so the
// reload serves the previously cached value fast instead of regenerating // reload serves the previously cached value fast instead of regenerating
...@@ -40,24 +38,23 @@ describe('use-cache-size-zero', () => { ...@@ -40,24 +38,23 @@ describe('use-cache-size-zero', () => {
// background revalidation regenerates a fresh entry for the next reload // background revalidation regenerates a fresh entry for the next reload
// (asserted below). // (asserted below).
await browser.refresh({ waitUntil: 'commit' }) await browser.refresh({ waitUntil: 'commit' })
await retry(async () => {
expect( expect(
await browser.elementByCss('p', { waitUntil: false }).text() await browser.elementByCss('#value', { waitUntil: false }).text()
).toBeDateString() ).toBe(coldValue)
})
expect(await browser.elementByCss('p', { waitUntil: false }).text()).toBe(
coldValue
)
// That warm reload regenerated a fresh entry in the background, so a later // That warm reload regenerates a fresh entry in the background. Poll with
// reload converges to the new value. Read after "load" here (a plain // independent requests so we can observe convergence without navigating
// refresh) since we want the settled value, not the streaming inspection // away from (and potentially cancelling) the warm browser request.
// above.
await retry(async () => { await retry(async () => {
const $ = await next.render$('/reload')
expect($('#value').text()).not.toBe(coldValue)
})
// Once independent requests observe convergence, confirm the next browser
// reload also exposes a fresh value through the user-visible path.
await browser.refresh() await browser.refresh()
expect(await browser.elementById('value').text()).not.toBe(coldValue) expect(await browser.elementById('value').text()).not.toBe(coldValue)
}) })
})
it('shows the Cold cache badge on an initial cold load and not on a warm reload', async () => { it('shows the Cold cache badge on an initial cold load and not on a warm reload', async () => {
const browser = await next.browser('/cold-badge') const browser = await next.browser('/cold-badge')
......
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