-
Notifications
You must be signed in to change notification settings - Fork 29.9k
[test] Deflake root-optional-revalidate #85584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eps1lon
merged 2 commits into
canary
from
sebbie/10-30-_test_deflake_root-optional-revalidate
Nov 3, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 0 additions & 76 deletions
76
test/integration/root-optional-revalidate/test/index.test.js
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
test/integration/root-optional-revalidate/test/index.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import type { ChildProcess } from 'child_process' | ||
| import { join } from 'path' | ||
| import cheerio from 'cheerio' | ||
| import { | ||
| killApp, | ||
| findPort, | ||
| nextBuild, | ||
| nextStart, | ||
| renderViaHTTP, | ||
| waitFor, | ||
| retry, | ||
| } from 'next-test-utils' | ||
|
|
||
| const appDir = join(__dirname, '../') | ||
| let app: ChildProcess | undefined | ||
| let appPort: number | undefined | ||
|
|
||
| const getProps = async (path) => { | ||
| const html = await renderViaHTTP(appPort, path) | ||
| const $ = cheerio.load(html) | ||
| return JSON.parse($('#props').text()) | ||
| } | ||
|
|
||
| const runTests = () => { | ||
| it('should render / correctly', async () => { | ||
| const props = await getProps('/') | ||
| expect(props.params).toEqual({}) | ||
|
|
||
| let cliOutput = '' | ||
| app.stdout.on('data', (chunk) => (cliOutput += chunk.toString())) | ||
| await waitFor(1000) | ||
| await getProps('/') | ||
| expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n') | ||
|
|
||
| // Rendering takes time before the new cache entry is filled | ||
| await retry(async () => { | ||
| const newProps = await getProps('/') | ||
| expect(newProps.params).toEqual({}) | ||
| expect(props.random).not.toBe(newProps.random) | ||
| }) | ||
| }) | ||
|
|
||
| it('should render /a correctly', async () => { | ||
| const props = await getProps('/a') | ||
| expect(props.params).toEqual({ slug: ['a'] }) | ||
|
|
||
| let cliOutput = '' | ||
| app.stdout.on('data', (chunk) => (cliOutput += chunk.toString())) | ||
| await waitFor(1000) | ||
| await getProps('/a') | ||
| expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n') | ||
|
|
||
| // Rendering takes time before the new cache entry is filled | ||
| await retry(async () => { | ||
| const newProps = await getProps('/a') | ||
| expect(newProps.params).toEqual({ slug: ['a'] }) | ||
| expect(props.random).not.toBe(newProps.random) | ||
| }) | ||
| }) | ||
|
|
||
| it('should render /hello/world correctly', async () => { | ||
| const props = await getProps('/hello/world') | ||
| expect(props.params).toEqual({ slug: ['hello', 'world'] }) | ||
|
|
||
| let cliOutput = '' | ||
| app.stdout.on('data', (chunk) => (cliOutput += chunk.toString())) | ||
| await waitFor(1000) | ||
| await getProps('/hello/world') | ||
| expect(cliOutput).toEqual('getStaticProps({ revalidateReason: "stale" })\n') | ||
|
|
||
| // Rendering takes time before the new cache entry is filled | ||
| await retry(async () => { | ||
| const newProps = await getProps('/hello/world') | ||
| expect(newProps.params).toEqual({ slug: ['hello', 'world'] }) | ||
| expect(props.random).not.toBe(newProps.random) | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| describe('Root Optional Catch-all Revalidate', () => { | ||
| ;(process.env.TURBOPACK_DEV ? describe.skip : describe)( | ||
| 'production mode', | ||
| () => { | ||
| beforeAll(async () => { | ||
| await nextBuild(appDir) | ||
| appPort = await findPort() | ||
| app = await nextStart(appDir, appPort) | ||
| }) | ||
| afterAll(() => killApp(app)) | ||
|
|
||
| runTests() | ||
| } | ||
| ) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test checks stdout immediately after triggering revalidation, but revalidation happens asynchronously in the background. This creates a race condition where the console.log output might not have arrived at the stdout listener yet when the expectation runs.
View Details
📝 Patch Details
Analysis
Race condition in root-optional-revalidate test - stdout check without async handling
What fails: The test checks stdout output from
getStaticPropsimmediately after triggering revalidation, but the output hasn't arrived yet due to Next.js ISR's asynchronous background revalidation pattern.How to reproduce: Running the tests for root-optional-revalidate will intermittently fail because the stdout output from
getStaticProps({ revalidateReason: "stale" })isn't captured when checked immediately after the HTTP request completes.Run this multiple times to see intermittent failures on the stdout expectation at lines 34, 52, and 70.
Result: Test fails with:
Expected: The stdout expectation should use
retry()to wait for the background revalidation to complete and executegetStaticProps, similar to how the test already correctly usesretry()for checking the new props after revalidation.Root cause: Next.js's response-cache returns the old cached entry to the HTTP client immediately via
resolve(), then schedules revalidation onprocess.nextTick(). When the test awaits the HTTP request and immediately checks the stdout, theprocess.nextTick()callback hasn't executed yet, sogetStaticPropshasn't been called and its console output isn't captured.Solution: Wrap the stdout expectation in
await retry()to handle the asynchronous nature of background revalidation, matching the existing pattern used for checking the updated props.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure but we can't just retry since that would hide if we're suddenly revalidating after 5s instead. There's no way around that if you're observing another process.