@@ -2490,6 +2490,48 @@ it.effect(
24902490 } ) ,
24912491) ;
24922492
2493+ it . effect . each ( [ true , false ] ) (
2494+ "ProviderSessionManagerV2 only expires background work's idle pin when it can survive process exit (process-bound: %s)" ,
2495+ ( backgroundTasksEndWithProcess ) =>
2496+ Effect . gen ( function * ( ) {
2497+ const state = yield * Ref . make ( emptyState ) ;
2498+ const pending = yield * Ref . make ( true ) ;
2499+ const effect = Effect . gen ( function * ( ) {
2500+ const manager = yield * ProviderSessionManager . ProviderSessionManagerV2 ;
2501+ const { providerSessionId, rosters } = yield * openSessionWithBackgroundCommand (
2502+ "provider-session-manager-background-pin" ,
2503+ ) ;
2504+
2505+ yield * TestClock . adjust ( "5 hours" ) ;
2506+
2507+ assert . equal ( yield * manager . isLive ( providerSessionId ) , backgroundTasksEndWithProcess ) ;
2508+ assert . equal ( ( yield * Ref . get ( state ) ) . closeCount , backgroundTasksEndWithProcess ? 0 : 1 ) ;
2509+ assert . deepStrictEqual ( yield * rosters , [ [ "dev-server" ] , [ "dev-server" ] ] ) ;
2510+
2511+ yield * Ref . set ( pending , false ) ;
2512+ yield * TestClock . adjust ( "30 minutes" ) ;
2513+
2514+ assert . isFalse ( yield * manager . isLive ( providerSessionId ) ) ;
2515+ assert . equal ( ( yield * Ref . get ( state ) ) . closeCount , 1 ) ;
2516+ assert . deepStrictEqual ( yield * rosters , [
2517+ backgroundTasksEndWithProcess ? [ ] : [ "dev-server" ] ,
2518+ [ "dev-server" ] ,
2519+ ] ) ;
2520+ } ) ;
2521+
2522+ yield * effect . pipe (
2523+ Effect . provide (
2524+ layerTest ( {
2525+ state,
2526+ idleTimeoutMs : 30 * 60_000 ,
2527+ backgroundTasksEndWithProcess,
2528+ hasPendingBackgroundWork : Ref . get ( pending ) ,
2529+ } ) ,
2530+ ) ,
2531+ ) ;
2532+ } ) ,
2533+ ) ;
2534+
24932535it . effect ( "ProviderSessionManagerV2 keeps the roster of a runtime whose tasks can outlive it" , ( ) =>
24942536 Effect . gen ( function * ( ) {
24952537 const state = yield * Ref . make ( emptyState ) ;
0 commit comments