Unverified Commit f7f2036e authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

test: stabilize after() deploy revalidation checks (#96428)

## Summary

[PR #96354](https://github.com/vercel/next.js/pull/96354) changed
`retry()` to enforce its duration as a wall-clock budget instead of
effectively treating it as a retry count. This exposed the test’s
previous two-second budget, which did not reliably cover the intentional
one-second `after()` delay plus deployment and ISR latency.

Separates the callback delay from the ISR settling timeout and waits for
timestamp reads to stabilize before establishing a baseline.

<!-- NEXT_JS_LLM -->
parent 43916339
...@@ -5,6 +5,10 @@ import { retry } from 'next-test-utils' ...@@ -5,6 +5,10 @@ import { retry } from 'next-test-utils'
const runtimes = ['nodejs', 'edge'] const runtimes = ['nodejs', 'edge']
const WAIT_BEFORE_REVALIDATING = 1000 const WAIT_BEFORE_REVALIDATING = 1000
const REVALIDATION_SETTLE_TIMEOUT = 15_000
const REVALIDATION_POLL_INTERVAL = 1000
const REVALIDATION_RETRY_DURATION =
WAIT_BEFORE_REVALIDATING + REVALIDATION_SETTLE_TIMEOUT
// If we want to verify that `after()` ran its callback, // If we want to verify that `after()` ran its callback,
// we need it to perform some kind of side effect (because it can't affect the response). // we need it to perform some kind of side effect (because it can't affect the response).
...@@ -21,7 +25,6 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => { ...@@ -21,7 +25,6 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => {
files: __dirname, files: __dirname,
env: { WAIT_BEFORE_REVALIDATING: WAIT_BEFORE_REVALIDATING + '' }, env: { WAIT_BEFORE_REVALIDATING: WAIT_BEFORE_REVALIDATING + '' },
}) })
const retryDuration = WAIT_BEFORE_REVALIDATING * 2
if (skipped) return if (skipped) return
const pathPrefix = '/' + runtimeValue const pathPrefix = '/' + runtimeValue
...@@ -50,9 +53,19 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => { ...@@ -50,9 +53,19 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => {
await getTimestampPageData(path) await getTimestampPageData(path)
} }
const data = await getTimestampPageData(path) // A previous test attempt may leave an ISR revalidation in progress. Wait
expect(data).toEqual(await getTimestampPageData(path)) // sanity check that it's static // for two consecutive reads to agree before using the timestamp as the
return data // baseline for this attempt.
return retry(
async () => {
const data = await getTimestampPageData(path)
expect(data).toEqual(await getTimestampPageData(path))
return data
},
REVALIDATION_SETTLE_TIMEOUT,
REVALIDATION_POLL_INTERVAL,
'wait for timestamp page cache to settle'
)
} }
it('triggers revalidate from a page', async () => { it('triggers revalidate from a page', async () => {
...@@ -66,8 +79,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => { ...@@ -66,8 +79,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => {
const dataAfter = await getTimestampPageData(path) const dataAfter = await getTimestampPageData(path)
expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp) expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp)
}, },
retryDuration, REVALIDATION_RETRY_DURATION,
1000, REVALIDATION_POLL_INTERVAL,
'check if timestamp page updated' 'check if timestamp page updated'
) )
}) })
...@@ -84,8 +97,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => { ...@@ -84,8 +97,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => {
const dataAfter = await getTimestampPageData(path) const dataAfter = await getTimestampPageData(path)
expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp) expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp)
}, },
retryDuration, REVALIDATION_RETRY_DURATION,
1000, REVALIDATION_POLL_INTERVAL,
'check if timestamp page updated' 'check if timestamp page updated'
) )
}) })
...@@ -101,8 +114,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => { ...@@ -101,8 +114,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => {
const dataAfter = await getTimestampPageData(path) const dataAfter = await getTimestampPageData(path)
expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp) expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp)
}, },
retryDuration, REVALIDATION_RETRY_DURATION,
1000, REVALIDATION_POLL_INTERVAL,
'check if timestamp page updated' 'check if timestamp page updated'
) )
}) })
...@@ -118,8 +131,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => { ...@@ -118,8 +131,8 @@ _describe.each(runtimes)('after() in %s runtime', (runtimeValue) => {
const dataAfter = await getTimestampPageData(path) const dataAfter = await getTimestampPageData(path)
expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp) expect(dataAfter.timestamp).toBeGreaterThan(dataBefore.timestamp)
}, },
retryDuration, REVALIDATION_RETRY_DURATION,
1000, REVALIDATION_POLL_INTERVAL,
'check if timestamp page updated' 'check if timestamp page updated'
) )
}) })
......
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