@@ -67,6 +67,27 @@ async function waitForPort(host, port, timeoutMs) {
6767 throw new Error ( `Timed out waiting for ${ host } :${ port } ` ) ;
6868}
6969
70+ async function waitForManagedServerReadiness ( { host, port, timeoutMs, child, logDir } ) {
71+ const deadline = Date . now ( ) + timeoutMs ;
72+ while ( Date . now ( ) < deadline ) {
73+ if ( child . exitCode != null || child . signalCode != null ) {
74+ throw createManagedServerError (
75+ `Managed E2E web server exited before ready (code=${ child . exitCode ?? 'null' } , signal=${ child . signalCode ?? 'null' } )` ,
76+ logDir ,
77+ ) ;
78+ }
79+ if ( await isPortOpen ( host , port ) ) return ;
80+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
81+ }
82+ if ( child . exitCode != null || child . signalCode != null ) {
83+ throw createManagedServerError (
84+ `Managed E2E web server exited before ready (code=${ child . exitCode ?? 'null' } , signal=${ child . signalCode ?? 'null' } )` ,
85+ logDir ,
86+ ) ;
87+ }
88+ throw new Error ( `Timed out waiting for ${ host } :${ port } ` ) ;
89+ }
90+
7091async function ensureCleanLogDir ( logDir ) {
7192 await fsp . rm ( logDir , { recursive : true , force : true } ) ;
7293 await fsp . mkdir ( logDir , { recursive : true } ) ;
@@ -199,7 +220,10 @@ async function startManagedExternalWebServer({
199220 } ) ;
200221
201222 try {
202- await Promise . race ( [ waitForPort ( host , port , timeoutMs ) , unexpectedExit ] ) ;
223+ await Promise . race ( [
224+ waitForManagedServerReadiness ( { host, port, timeoutMs, child, logDir } ) ,
225+ unexpectedExit ,
226+ ] ) ;
203227 } catch ( error ) {
204228 cleanup ( ) ;
205229 throw error ;
0 commit comments