@@ -1054,6 +1054,19 @@ describe("DesktopBackendManager", () => {
10541054 it . effect ( "restarts an unexpectedly exited backend with the Effect clock" , ( ) =>
10551055 Effect . scoped (
10561056 Effect . gen ( function * ( ) {
1057+ const waitForNextSpawn = Effect . gen ( function * ( ) {
1058+ const sc = typeof startCount !== 'undefined' ? startCount : spawnCount ;
1059+ while ( true ) {
1060+ const state = yield * instance . snapshot ;
1061+ if ( ! state . desiredRunning ) break ;
1062+ const currentSc = typeof startCount !== 'undefined' ? startCount : spawnCount ;
1063+ if ( currentSc > sc ) break ;
1064+ if ( state . ready ) break ;
1065+ if ( state . restartFiber && state . restartFiber . _tag === "Some" ) break ;
1066+ yield * Effect . yieldNow ;
1067+ }
1068+ } ) ;
1069+
10571070 const starts = yield * Queue . unbounded < number > ( ) ;
10581071 const failures = yield * Queue . unbounded < string > ( ) ;
10591072 let startCount = 0 ;
@@ -1401,6 +1414,19 @@ describe("DesktopBackendManager", () => {
14011414 it . effect ( "never-ready cap invokes onPreflightFailed exactly once and stops when false" , ( ) =>
14021415 Effect . scoped (
14031416 Effect . gen ( function * ( ) {
1417+ const waitForNextSpawn = Effect . gen ( function * ( ) {
1418+ const sc = typeof startCount !== 'undefined' ? startCount : spawnCount ;
1419+ while ( true ) {
1420+ const state = yield * instance . snapshot ;
1421+ if ( ! state . desiredRunning ) break ;
1422+ const currentSc = typeof startCount !== 'undefined' ? startCount : spawnCount ;
1423+ if ( currentSc > sc ) break ;
1424+ if ( state . ready ) break ;
1425+ if ( state . restartFiber && state . restartFiber . _tag === "Some" ) break ;
1426+ yield * Effect . yieldNow ;
1427+ }
1428+ } ) ;
1429+
14041430 let spawnCount = 0 ;
14051431 let preflightFailedCount = 0 ;
14061432 let lastPreflightFailure : DesktopBackendManager . PreflightFailure | undefined ;
@@ -1435,8 +1461,8 @@ describe("DesktopBackendManager", () => {
14351461 } ) ;
14361462
14371463 yield * instance . start ;
1438- yield * TestClock . adjust ( Duration . millis ( 500 ) ) ;
1439- yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
1464+ yield * waitForNextSpawn ; yield * TestClock . adjust ( Duration . millis ( 500 ) ) ;
1465+ yield * waitForNextSpawn ; yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
14401466 yield * TestClock . adjust ( Duration . seconds ( 2 ) ) ;
14411467 yield * TestClock . adjust ( Duration . seconds ( 4 ) ) ;
14421468 yield * Deferred . await ( preflightFailed ) ;
@@ -1457,6 +1483,19 @@ describe("DesktopBackendManager", () => {
14571483 it . effect ( "readiness resets the never-ready cap for stdin-delivery backends" , ( ) =>
14581484 Effect . scoped (
14591485 Effect . gen ( function * ( ) {
1486+ const waitForNextSpawn = Effect . gen ( function * ( ) {
1487+ const sc = typeof startCount !== 'undefined' ? startCount : spawnCount ;
1488+ while ( true ) {
1489+ const state = yield * instance . snapshot ;
1490+ if ( ! state . desiredRunning ) break ;
1491+ const currentSc = typeof startCount !== 'undefined' ? startCount : spawnCount ;
1492+ if ( currentSc > sc ) break ;
1493+ if ( state . ready ) break ;
1494+ if ( state . restartFiber && state . restartFiber . _tag === "Some" ) break ;
1495+ yield * Effect . yieldNow ;
1496+ }
1497+ } ) ;
1498+
14601499 let spawnCount = 0 ;
14611500 let preflightFailedCount = 0 ;
14621501 const preflightFailed = yield * Deferred . make < void > ( ) ;
@@ -1504,8 +1543,8 @@ describe("DesktopBackendManager", () => {
15041543 } ) ;
15051544
15061545 yield * instance . start ;
1507- yield * TestClock . adjust ( Duration . millis ( 500 ) ) ;
1508- yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
1546+ yield * waitForNextSpawn ; yield * TestClock . adjust ( Duration . millis ( 500 ) ) ;
1547+ yield * waitForNextSpawn ; yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
15091548 yield * TestClock . adjust ( Duration . seconds ( 2 ) ) ;
15101549 yield * TestClock . adjust ( Duration . seconds ( 4 ) ) ;
15111550 // Wait for the 5th spawn to become ready
@@ -1518,8 +1557,8 @@ describe("DesktopBackendManager", () => {
15181557 yield * Deferred . succeed ( closeReadyProcess , void 0 ) ;
15191558
15201559 // Now advance time for the next 4 failures before readiness
1521- yield * TestClock . adjust ( Duration . millis ( 500 ) ) ;
1522- yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
1560+ yield * waitForNextSpawn ; yield * TestClock . adjust ( Duration . millis ( 500 ) ) ;
1561+ yield * waitForNextSpawn ; yield * TestClock . adjust ( Duration . seconds ( 1 ) ) ;
15231562 yield * TestClock . adjust ( Duration . seconds ( 2 ) ) ;
15241563 yield * TestClock . adjust ( Duration . seconds ( 4 ) ) ;
15251564
0 commit comments