@@ -631,4 +631,42 @@ describe("DesktopBackendManager", () => {
631631 } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
632632 ) ,
633633 ) ;
634+
635+ it . effect ( "waits out a slow startup and reports one that never becomes ready" , ( ) =>
636+ Effect . scoped (
637+ Effect . gen ( function * ( ) {
638+ const reports = yield * Queue . unbounded < DesktopBackendManager . BackendStartupFailure > ( ) ;
639+ const startInstance = ( status : Ref . Ref < number > , onReady ?: Effect . Effect < void > ) =>
640+ makeTestInstance ( {
641+ spawnerLayer : Layer . succeed (
642+ ChildProcessSpawner . ChildProcessSpawner ,
643+ ChildProcessSpawner . make ( ( ) =>
644+ Effect . succeed ( makeProcess ( { exitCode : Effect . never } ) ) ,
645+ ) ,
646+ ) ,
647+ httpClientLayer : layerHttpClient ( ( request ) =>
648+ Ref . get ( status ) . pipe ( Effect . map ( ( code ) => responseForRequest ( request , code ) ) ) ,
649+ ) ,
650+ onStartupFailure : ( failure ) => Queue . offer ( reports , failure ) . pipe ( Effect . asVoid ) ,
651+ ...( onReady ? { onReady } : { } ) ,
652+ } ) . pipe ( Effect . tap ( ( instance ) => instance . start ) ) ;
653+
654+ const slowStatus = yield * Ref . make ( 503 ) ;
655+ const ready = yield * Deferred . make < void > ( ) ;
656+ yield * startInstance ( slowStatus , Deferred . succeed ( ready , undefined ) . pipe ( Effect . asVoid ) ) ;
657+ yield * TestClock . adjust ( Duration . seconds ( 66 ) ) ;
658+ yield * Ref . set ( slowStatus , 200 ) ;
659+ yield * TestClock . adjust ( Duration . millis ( 100 ) ) ;
660+ yield * Deferred . await ( ready ) ;
661+ assert . isTrue ( Option . isNone ( yield * Queue . poll ( reports ) ) ) ;
662+
663+ yield * startInstance ( yield * Ref . make ( 503 ) ) ;
664+ yield * TestClock . adjust ( Duration . seconds ( 179 ) ) ;
665+ assert . isTrue ( Option . isNone ( yield * Queue . poll ( reports ) ) ) ;
666+ yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
667+ const failure = yield * Queue . take ( reports ) ;
668+ assert . equal ( failure . reason , "The server started but did not become ready in time." ) ;
669+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
670+ ) ,
671+ ) ;
634672} ) ;
0 commit comments