@@ -515,11 +515,20 @@ describe("environment RPC", () => {
515515 Effect . gen ( function * ( ) {
516516 const transient = new Error ( "transient snapshot failure" ) ;
517517 const subscriptionCount = yield * Ref . make ( 0 ) ;
518+ const retryReady = yield * Deferred . make < void > ( ) ;
519+ const retryStarted = yield * Deferred . make < void > ( ) ;
518520 const client = {
519521 [ WS_METHODS . subscribeTerminalEvents ] : ( ) =>
520522 Stream . unwrap (
521523 Ref . getAndUpdate ( subscriptionCount , ( count ) => count + 1 ) . pipe (
522- Effect . map ( ( count ) => ( count === 0 ? Stream . fail ( transient ) : Stream . never ) ) ,
524+ Effect . map ( ( count ) =>
525+ count === 0
526+ ? Stream . fail ( transient )
527+ : Stream . fromEffect ( Deferred . succeed ( retryStarted , undefined ) ) . pipe (
528+ Stream . drain ,
529+ Stream . concat ( Stream . never ) ,
530+ ) ,
531+ ) ,
523532 ) ,
524533 ) ,
525534 } as unknown as WsRpcProtocolClient ;
@@ -530,7 +539,7 @@ describe("environment RPC", () => {
530539 WS_METHODS . subscribeTerminalEvents ,
531540 { } ,
532541 {
533- onExpectedFailure : ( ) => Effect . void ,
542+ onExpectedFailure : ( ) => Deferred . succeed ( retryReady , undefined ) . pipe ( Effect . asVoid ) ,
534543 retryExpectedFailureAfter : "100 millis" ,
535544 terminalFailure : {
536545 matches : ( ) => false ,
@@ -543,19 +552,11 @@ describe("environment RPC", () => {
543552 Effect . forkChild ,
544553 ) ;
545554
546- // The retry sleep must be scheduled before virtual time advances.
547- for (
548- let attempt = 0 ;
549- attempt < 100 && ( yield * Ref . get ( subscriptionCount ) ) < 1 ;
550- attempt += 1
551- ) {
552- yield * Effect . yieldNow ;
553- }
555+ // The handler runs immediately before the retry delay; let that fiber schedule its sleep.
556+ yield * Deferred . await ( retryReady ) ;
557+ yield * Effect . yieldNow ;
554558 yield * TestClock . adjust ( "100 millis" ) ;
555- for ( let attempt = 0 ; attempt < 100 ; attempt += 1 ) {
556- if ( ( yield * Ref . get ( subscriptionCount ) ) >= 2 ) break ;
557- yield * Effect . yieldNow ;
558- }
559+ yield * Deferred . await ( retryStarted ) ;
559560 yield * Fiber . interrupt ( subscriptionFiber ) ;
560561
561562 // Classified as a regular expected failure: retried once, handler untouched.
0 commit comments