Fix flaky metadata-static-route-cache test: wrap server lifecycle in try/finally#91916
Fix flaky metadata-static-route-cache test: wrap server lifecycle in try/finally#91916
Conversation
…le in try/finally Each next.start() is now paired with a finally block that calls next.stop(), ensuring the server is stopped even when assertions throw mid-test. Without this, a failed test left the server running, causing "next already started" on retry. Co-Authored-By: Claude <noreply@anthropic.com>
Failing test suitesCommit: 5a5d6a6 | About building and testing Next.js
Expand output● use-cache-without-experimental-flag › should recover from the build error if useCache flag is set
Expand output● after() in static pages › runs after during build
Expand output● Image Component Default Tests › production mode › should load the images ● Image Component Default Tests › production mode › should preload priority images ● Image Component Default Tests › production mode › should work with preload prop ● Image Component Default Tests › production mode › should not pass through user-provided srcset (causing a flash) ● Image Component Default Tests › production mode › should update the image on src change ● Image Component Default Tests › production mode › should callback onLoadingComplete when image is fully loaded ● Image Component Default Tests › production mode › should callback native onLoad with sythetic event ● Image Component Default Tests › production mode › should callback native onError when error occurred while loading image ● Image Component Default Tests › production mode › should callback native onError even when error before hydration ● Image Component Default Tests › production mode › should work with image with blob src ● Image Component Default Tests › production mode › should work when using flexbox ● Image Component Default Tests › production mode › should work when using overrideSrc prop ● Image Component Default Tests › production mode › should work with sizes and automatically use responsive srcset ● Image Component Default Tests › production mode › should render no wrappers or sizers ● Image Component Default Tests › production mode › should lazy load with placeholder=blur ● Image Component Default Tests › production mode › should handle the styles prop appropriately ● Image Component Default Tests › production mode › should warn when legacy prop layout=fill ● Image Component Default Tests › production mode › should warn when legacy prop layout=responsive ● Image Component Default Tests › production mode › should render picture via getImageProps ● Image Component Default Tests › production mode › should not create an image folder in server/chunks ● Image Component Default Tests › production mode › should render as unoptimized with missing src prop ● Image Component Default Tests › production mode › should render as unoptimized with empty string src prop ● Image Component Default Tests › production mode › should correctly ignore prose styles ● Image Component Default Tests › production mode › should apply style inheritance for img elements but not wrapper elements ● Image Component Default Tests › production mode › should apply filter style after image loads ● Image Component Default Tests › production mode › should emit image for next/dynamic with non ssr case ● Image Component Default Tests › production mode › Fill-mode tests › should include a data-attribute on fill images ● Image Component Default Tests › production mode › Fill-mode tests › should include a data-attribute on fill images ● Image Component Default Tests › production mode › Fill-mode tests › should add position:absolute to fill images ● Image Component Default Tests › production mode › Fill-mode tests › should add position:absolute to fill images ● Image Component Default Tests › production mode › Fill-mode tests › should add 100% width and height to fill images ● Image Component Default Tests › production mode › Fill-mode tests › should add 100% width and height to fill images ● Image Component Default Tests › production mode › Fill-mode tests › should add position styles to fill images ● Image Component Default Tests › production mode › Fill-mode tests › should add position styles to fill images ● Image Component Default Tests › production mode › should correctly rotate image ● Image Component Default Tests › production mode › should have data url placeholder when enabled ● Image Component Default Tests › production mode › should remove data url placeholder after image loads ● Image Component Default Tests › production mode › should render correct objectFit when data url placeholder and fill ● Image Component Default Tests › production mode › should have blurry placeholder when enabled ● Image Component Default Tests › production mode › should remove blurry placeholder after image loads ● Image Component Default Tests › production mode › should render correct objectFit when blurDataURL and fill ● Image Component Default Tests › production mode › should be valid HTML ● Image Component Default Tests › production mode › should call callback ref cleanups when unmounting ● Image Component Default Tests › production mode › should build correct images-manifest.json
Expand output● segment cache - vary params › renders cached loading state instantly with runtime prefetching ● segment cache - vary params › tracks vary params per-segment with layout/page split (runtime prefetch)
Expand output● proxy-missing-export › should NOT error when proxy file has a default function export ● proxy-missing-export › should NOT error when proxy file has a default arrow function export ● proxy-missing-export › should NOT error when proxy file has a named declaration function export ● proxy-missing-export › should NOT error when proxy file has a named declaration arrow function export ● proxy-missing-export › should error when proxy file has a named export with different name alias |
Stats from current PR🔴 2 regressions
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
Fixing a bug
What?
Fixes the flaky test in
test/production/app-dir/metadata-static-route-cache/metadata-static-route-cache.test.ts:Why?
The test uses
skipStart: trueand manually callsnext.start()/next.stop()twice within a singleitblock (once to capture initial hashes, once after swapping static files to verify new hashes). Thenext.stop()calls only ran on the happy path — if any assertion or network fetch threw betweenstart()andstop(), the server was left running. On a test retry (or Jest's automatic retry), the nextnext.start()call would fail immediately withError: next already started.How?
Wrapped both
start()/stop()pairs intry/finallyblocks sonext.stop()is always called regardless of whether the body throws:No changes to test logic or fixtures — only the server lifecycle safety is improved.
Verified stable: ran the test 3 times consecutively with
NEXT_SKIP_ISOLATE=1 NEXT_TEST_MODE=start, all passed.