@@ -631,38 +631,7 @@ describe('Hooks E2E Tests', () => {
631631 } , 20000 )
632632
633633 test ( 'should handle async fallback response generation' , async ( ) => {
634- // Create a new failing server for this test
635- const asyncFailingPort = Math . floor ( Math . random ( ) * 10000 ) + 56000
636- const asyncFailingServer = Bun . serve ( {
637- port : asyncFailingPort ,
638- fetch : async ( req ) => {
639- const url = new URL ( req . url )
640- if ( url . pathname === '/error' ) {
641- return new Response ( 'Server error' , { status : 500 } )
642- }
643- return new Response ( 'OK' , { status : 200 } )
644- } ,
645- } as Parameters < typeof Bun . serve > [ 0 ] )
646-
647- // Wait for the failing server to be ready (allow extra time for slow CI runners)
648- let failingServerReady = false
649- for ( let i = 0 ; i < 100 ; i ++ ) {
650- try {
651- const healthCheck = await fetch ( `http://localhost:${ asyncFailingPort } /` )
652- if ( healthCheck . status === 200 ) {
653- failingServerReady = true
654- break
655- }
656- } catch {
657- await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) )
658- }
659- }
660- if ( ! failingServerReady ) {
661- asyncFailingServer . stop ( )
662- throw new Error ( 'Failing server failed to start' )
663- }
664-
665- // Create a new gateway with async onError hook
634+ // Reuse the shared failing server so we do not re-flake on CI server startup
666635 const asyncGatewayPort = Math . floor ( Math . random ( ) * 10000 ) + 53000
667636 const asyncGateway = new BunGateway ( {
668637 server : {
@@ -674,7 +643,7 @@ describe('Hooks E2E Tests', () => {
674643
675644 const asyncRouteConfig : RouteConfig = {
676645 pattern : '/api/async-fallback/*' ,
677- target : `http://localhost:${ asyncFailingPort } ` ,
646+ target : `http://localhost:${ failingPort } ` ,
678647 timeout : 5000 ,
679648 proxy : {
680649 pathRewrite : {
@@ -728,7 +697,6 @@ describe('Hooks E2E Tests', () => {
728697 }
729698 if ( ! gatewayReady ) {
730699 asyncServer . stop ( )
731- asyncFailingServer . stop ( )
732700 throw new Error ( 'Gateway server failed to start' )
733701 }
734702
@@ -755,7 +723,6 @@ describe('Hooks E2E Tests', () => {
755723 )
756724 } finally {
757725 asyncServer . stop ( )
758- asyncFailingServer . stop ( )
759726 }
760727 } , 30000 )
761728} )
0 commit comments