@@ -157,7 +157,7 @@ const makeHarness = Effect.fn("TestConnectionHarness.make")(function* (options?:
157157 ) => Effect . Effect < PreparedConnection , ConnectionAttemptError > ;
158158 readonly ready ?: ( attempt : number ) => Effect . Effect < void , ConnectionAttemptError > ;
159159 readonly probe ?: ( attempt : number ) => Effect . Effect < void , ConnectionAttemptError > ;
160- readonly receivedFrames ?: Effect . Effect < number > ;
160+ readonly receivedReads ?: Effect . Effect < number > ;
161161 readonly initialConfig ?: ( attempt : number ) => Effect . Effect < ServerConfig , ConnectionAttemptError > ;
162162 readonly checkRoute ?: ( route : ConnectionRoute ) => Effect . Effect < ConnectionDriver . RouteCheck > ;
163163} ) {
@@ -214,7 +214,7 @@ const makeHarness = Effect.fn("TestConnectionHarness.make")(function* (options?:
214214 subscribeServerConfig : ( input ) => TEST_RPC_CLIENT . subscribeServerConfig ( input ) ,
215215 ready : options ?. ready ?.( attempt ) ?? Effect . void ,
216216 probe : options ?. probe ?.( attempt ) ?? Effect . void ,
217- receivedFrames : options ?. receivedFrames ?? Effect . succeed ( 0 ) ,
217+ receivedReads : options ?. receivedReads ?? Effect . succeed ( 0 ) ,
218218 closed : Deferred . await ( closed ) ,
219219 } satisfies RpcSession . RpcSession ) ,
220220 ( ) => Ref . update ( releaseCount , ( count ) => count + 1 ) ,
@@ -628,6 +628,42 @@ describe("EnvironmentSupervisor", () => {
628628 } ) ,
629629 ) ;
630630
631+ it . effect ( "a mobile refocus restarts the retry ladder but never probes a live session" , ( ) =>
632+ Effect . gen ( function * ( ) {
633+ const probeCount = yield * Ref . make ( 0 ) ;
634+ const harness = yield * makeHarness ( {
635+ prepare : ( attempt ) =>
636+ attempt <= 2 ? Effect . fail ( transient ( ) ) : Effect . succeed ( PREPARED_CONNECTION ) ,
637+ probe : ( ) => Ref . update ( probeCount , ( count ) => count + 1 ) ,
638+ } ) ;
639+ const supervisor = yield * EnvironmentSupervisor . make ( TARGET_ENTRY , {
640+ initiallyDesired : true ,
641+ } ) . pipe ( Effect . provide ( harness . dependencies ) ) ;
642+
643+ yield * awaitState (
644+ supervisor . state ,
645+ ( state ) => state . phase === "backoff" && state . attempt === 1 ,
646+ ) ;
647+ yield * TestClock . adjust ( "3 seconds" ) ;
648+ yield * eventuallyState (
649+ supervisor . state ,
650+ ( state ) => state . phase === "backoff" && state . attempt === 2 ,
651+ ) ;
652+ yield * harness . wake ( "application-refocused" ) ;
653+ yield * eventuallyState (
654+ supervisor . state ,
655+ ( state ) => state . phase === "connected" && state . attempt === 1 ,
656+ ) ;
657+
658+ yield * harness . wake ( "application-refocused" ) ;
659+ for ( let attempt = 0 ; attempt < 100 ; attempt += 1 ) {
660+ yield * Effect . yieldNow ;
661+ }
662+ expect ( yield * Ref . get ( probeCount ) ) . toBe ( 0 ) ;
663+ expect ( yield * Ref . get ( harness . sessionCount ) ) . toBe ( 1 ) ;
664+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
665+ ) ;
666+
631667 it . effect ( "explicit retry starts a fresh backoff sequence" , ( ) =>
632668 Effect . gen ( function * ( ) {
633669 const harness = yield * makeHarness ( {
@@ -1328,6 +1364,35 @@ describe("EnvironmentSupervisor", () => {
13281364 } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
13291365 ) ;
13301366
1367+ it . effect ( "extends a retry-shortened probe by the retry's window when data arrives" , ( ) =>
1368+ Effect . gen ( function * ( ) {
1369+ const frames = yield * Ref . make ( 0 ) ;
1370+ const harness = yield * makeHarness ( {
1371+ probe : ( attempt ) => ( attempt === 1 ? Effect . never : Effect . void ) ,
1372+ receivedReads : Ref . get ( frames ) ,
1373+ } ) ;
1374+ const supervisor = yield * EnvironmentSupervisor . make ( TARGET_ENTRY , {
1375+ initiallyDesired : true ,
1376+ } ) . pipe ( Effect . provide ( harness . dependencies ) ) ;
1377+
1378+ yield * awaitState ( supervisor . state , ( state ) => state . phase === "connected" ) ;
1379+ yield * harness . wake ( "application-active" ) ;
1380+ yield * TestClock . adjust ( "1 second" ) ;
1381+ yield * supervisor . retryNow ;
1382+ yield * TestClock . adjust ( "1 second" ) ;
1383+ yield * Ref . set ( frames , 1 ) ;
1384+ // The retry's deadline lands at 7 seconds and the data extends it by the
1385+ // retry's 6 seconds to 13, not by the original 15.
1386+ yield * TestClock . adjust ( "10999 millis" ) ;
1387+ expect ( yield * Ref . get ( harness . sessionCount ) ) . toBe ( 1 ) ;
1388+ yield * TestClock . adjust ( "1 milli" ) ;
1389+ yield * awaitState (
1390+ supervisor . state ,
1391+ ( state ) => state . phase === "connected" && state . generation === 2 ,
1392+ ) ;
1393+ } ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
1394+ ) ;
1395+
13311396 it . effect ( "quickly times out a stalled mobile foreground liveness probe" , ( ) =>
13321397 Effect . gen ( function * ( ) {
13331398 const harness = yield * makeHarness ( {
@@ -1356,7 +1421,7 @@ describe("EnvironmentSupervisor", () => {
13561421 const frames = yield * Ref . make ( 0 ) ;
13571422 const harness = yield * makeHarness ( {
13581423 probe : ( attempt ) => ( attempt === 1 ? Effect . never : Effect . void ) ,
1359- receivedFrames : Ref . get ( frames ) ,
1424+ receivedReads : Ref . get ( frames ) ,
13601425 } ) ;
13611426 const supervisor = yield * EnvironmentSupervisor . make ( TARGET_ENTRY , {
13621427 initiallyDesired : true ,
@@ -1387,7 +1452,7 @@ describe("EnvironmentSupervisor", () => {
13871452 const frames = yield * Ref . make ( 0 ) ;
13881453 const harness = yield * makeHarness ( {
13891454 probe : ( attempt ) => ( attempt === 1 ? Effect . never : Effect . void ) ,
1390- receivedFrames : Ref . get ( frames ) ,
1455+ receivedReads : Ref . get ( frames ) ,
13911456 } ) ;
13921457 const supervisor = yield * EnvironmentSupervisor . make ( TARGET_ENTRY , {
13931458 initiallyDesired : true ,
0 commit comments