Skip to content

Commit 5224b82

Browse files
committed
test: assert SSG and persistence flush overlap in filesystem-cache test
Add a production-only test that reads the trace-build file and verifies that static-generation starts before turbopack-persistence finishes. This ensures SSG is not blocked on the Turbopack shutdown promise. Uses the startTime field (Date.now() epoch ms) which is comparable across the worker and parent processes.
1 parent 9c53d1c commit 5224b82

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/e2e/filesystem-cache/filesystem-cache.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,43 @@ for (const cacheEnabled of [false, true]) {
458458
expect(typeof tags.task_count).toBe('number')
459459
}
460460
)
461+
462+
// Production-only: verify that SSG runs in parallel with persistence
463+
// (not blocked waiting for the Turbopack shutdown to complete).
464+
;(process.env.IS_TURBOPACK_TEST && !isNextDev ? it : it.skip)(
465+
'should run SSG in parallel with persistence flush',
466+
async () => {
467+
// beforeEach already called start() which triggers a build.
468+
// The trace-build file was written during that build.
469+
const traceBuildPath = path.join(next.testDir, '.next/trace-build')
470+
expect(existsSync(traceBuildPath)).toBe(true)
471+
472+
const events = parseTraceFile(traceBuildPath)
473+
474+
const ssgEvents = events.filter((e) => e.name === 'static-generation')
475+
const persistenceEvents = events.filter(
476+
(e) => e.name === 'turbopack-persistence'
477+
)
478+
479+
expect(ssgEvents.length).toBe(1)
480+
expect(persistenceEvents.length).toBeGreaterThan(0)
481+
482+
const ssg = ssgEvents[0]
483+
const persistence = persistenceEvents[0]
484+
485+
// Both spans carry a startTime field (Date.now() epoch ms) that
486+
// is comparable across processes. For manualTraceChild spans
487+
// (like turbopack-persistence) startTime is set when the JS
488+
// side processes the event — roughly when persistence finishes.
489+
//
490+
// The key invariant: SSG must start before persistence finishes.
491+
// If SSG were blocked on the shutdown promise, it would only
492+
// start *after* persistence completes.
493+
expect(ssg.startTime).toBeDefined()
494+
expect(persistence.startTime).toBeDefined()
495+
expect(ssg.startTime).toBeLessThan(persistence.startTime!)
496+
}
497+
)
461498
}
462499
})
463500
}

0 commit comments

Comments
 (0)