@@ -776,55 +776,50 @@ describe("EnvironmentSupervisor", () => {
776776 } ) ,
777777 ) ;
778778
779- it . effect ( "keeps a live session through one slow foreground probe that later answers" , ( ) =>
780- Effect . gen ( function * ( ) {
781- const probeCalls = yield * Ref . make ( 0 ) ;
782- const firstProbeStarted = yield * Deferred . make < void > ( ) ;
783- const secondProbeAnswered = yield * Deferred . make < void > ( ) ;
784- const harness = yield * makeHarness ( {
785- probe : ( ) =>
786- Ref . updateAndGet ( probeCalls , ( count ) => count + 1 ) . pipe (
787- Effect . flatMap ( ( call ) =>
788- call === 1
789- ? Deferred . succeed ( firstProbeStarted , undefined ) . pipe ( Effect . andThen ( Effect . never ) )
790- : Deferred . succeed ( secondProbeAnswered , undefined ) ,
779+ it . effect (
780+ "keeps a live session when the automatic follow-up to a slow foreground probe answers" ,
781+ ( ) =>
782+ Effect . gen ( function * ( ) {
783+ const probeCount = yield * Ref . make ( 0 ) ;
784+ const probeStarted = yield * Queue . unbounded < number > ( ) ;
785+ const harness = yield * makeHarness ( {
786+ probe : ( ) =>
787+ Ref . updateAndGet ( probeCount , ( count ) => count + 1 ) . pipe (
788+ Effect . tap ( ( call ) => Queue . offer ( probeStarted , call ) ) ,
789+ Effect . flatMap ( ( call ) => ( call === 1 ? Effect . never : Effect . void ) ) ,
791790 ) ,
792- ) ,
793- } ) ;
794- const supervisor = yield * EnvironmentSupervisor . make ( TARGET_ENTRY , {
795- initiallyDesired : true ,
796- } ) . pipe ( Effect . provide ( harness . dependencies ) ) ;
797-
798- yield * awaitState (
799- supervisor . state ,
800- ( state ) => state . phase === "connected" && state . generation === 1 ,
801- ) ;
802- yield * harness . wake ( "application-active" ) ;
803- yield * Deferred . await ( firstProbeStarted ) ;
804- // A busy server misses the foreground probe deadline once; the socket
805- // never closed.
806- yield * TestClock . adjust ( "18 seconds" ) ;
807- yield * awaitState ( supervisor . state , ( state ) => state . phase === "connected" ) ;
808- yield * harness . wake ( "application-active" ) ;
809- yield * Deferred . await ( secondProbeAnswered ) ;
810-
811- expect ( yield * Ref . get ( harness . releaseCount ) ) . toBe ( 0 ) ;
812- expect ( yield * Ref . get ( harness . sessionCount ) ) . toBe ( 1 ) ;
813- expect ( ( yield * SubscriptionRef . get ( supervisor . state ) ) . generation ) . toBe ( 1 ) ;
814- } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
791+ } ) ;
792+ const supervisor = yield * EnvironmentSupervisor . make ( TARGET_ENTRY , {
793+ initiallyDesired : true ,
794+ } ) . pipe ( Effect . provide ( harness . dependencies ) ) ;
795+
796+ yield * awaitState (
797+ supervisor . state ,
798+ ( state ) => state . phase === "connected" && state . generation === 1 ,
799+ ) ;
800+ yield * harness . wake ( "application-active" ) ;
801+ expect ( yield * Queue . take ( probeStarted ) ) . toBe ( 1 ) ;
802+ // A busy server misses the foreground probe deadline once while the
803+ // socket stays open; the supervisor asks again on its own.
804+ yield * TestClock . adjust ( "15 seconds" ) ;
805+ expect ( yield * Queue . take ( probeStarted ) ) . toBe ( 2 ) ;
806+ yield * TestClock . adjust ( "30 seconds" ) ;
807+
808+ expect ( yield * Ref . get ( harness . releaseCount ) ) . toBe ( 0 ) ;
809+ expect ( yield * Ref . get ( harness . sessionCount ) ) . toBe ( 1 ) ;
810+ expect ( yield * SubscriptionRef . get ( supervisor . state ) ) . toMatchObject ( {
811+ phase : "connected" ,
812+ generation : 1 ,
813+ } ) ;
814+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
815815 ) ;
816816
817- it . effect ( "replaces a session after consecutive unanswered foreground probes " , ( ) =>
817+ it . effect ( "replaces a session when the automatic follow-up probe also goes unanswered " , ( ) =>
818818 Effect . gen ( function * ( ) {
819- const probeCalls = yield * Ref . make ( 0 ) ;
820- const probeStarted = yield * Queue . unbounded < number > ( ) ;
819+ const probeCount = yield * Ref . make ( 0 ) ;
821820 const harness = yield * makeHarness ( {
822- // Misses, answers, then misses twice in a row.
823821 probe : ( ) =>
824- Ref . updateAndGet ( probeCalls , ( count ) => count + 1 ) . pipe (
825- Effect . tap ( ( call ) => Queue . offer ( probeStarted , call ) ) ,
826- Effect . flatMap ( ( call ) => ( call === 2 ? Effect . void : Effect . never ) ) ,
827- ) ,
822+ Ref . update ( probeCount , ( count ) => count + 1 ) . pipe ( Effect . andThen ( Effect . never ) ) ,
828823 } ) ;
829824 const supervisor = yield * EnvironmentSupervisor . make ( TARGET_ENTRY , {
830825 initiallyDesired : true ,
@@ -834,21 +829,17 @@ describe("EnvironmentSupervisor", () => {
834829 supervisor . state ,
835830 ( state ) => state . phase === "connected" && state . generation === 1 ,
836831 ) ;
837- for ( const attempt of [ 1 , 2 , 3 ] ) {
838- yield * harness . wake ( "application-active" ) ;
839- expect ( yield * Queue . take ( probeStarted ) ) . toBe ( attempt ) ;
840- yield * TestClock . adjust ( "18 seconds" ) ;
841- }
842- // The answer in between reset the tolerance, so the session survives.
843- expect ( yield * Ref . get ( harness . releaseCount ) ) . toBe ( 0 ) ;
844-
832+ // One foreground event and no other signal: the follow-up's miss alone
833+ // replaces the session.
845834 yield * harness . wake ( "application-active" ) ;
846- expect ( yield * Queue . take ( probeStarted ) ) . toBe ( 4 ) ;
847- yield * TestClock . adjust ( "18 seconds" ) ;
835+ yield * TestClock . adjust ( "15 seconds" ) ;
836+ yield * TestClock . adjust ( "15 seconds" ) ;
848837 yield * awaitState (
849838 supervisor . state ,
850839 ( state ) => state . phase === "connected" && state . generation === 2 ,
851840 ) ;
841+
842+ expect ( yield * Ref . get ( probeCount ) ) . toBe ( 2 ) ;
852843 expect ( yield * Ref . get ( harness . releaseCount ) ) . toBe ( 1 ) ;
853844 } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
854845 ) ;
0 commit comments