@@ -106,6 +106,52 @@ describe("ssh tunnel scripts", () => {
106106 ) ;
107107 } ) ;
108108
109+ it . effect . each ( [
110+ { operation : "launch" , runner : "archive" } ,
111+ { operation : "launch" , runner : "node" } ,
112+ { operation : "pairing" , runner : "archive" } ,
113+ { operation : "pairing" , runner : "node" } ,
114+ ] as const ) ( "lets $runner $operation finish after a full lock wait" , ( { operation, runner } ) =>
115+ Effect . gen ( function * ( ) {
116+ const started = yield * Deferred . make < void > ( ) ;
117+ const finish = yield * Deferred . make < void > ( ) ;
118+ const spawner = ChildProcessSpawner . make ( ( ) =>
119+ Effect . gen ( function * ( ) {
120+ yield * Deferred . succeed ( started , undefined ) ;
121+ const result = operation === "launch" ? { remotePort : 3774 } : { credential : "test" } ;
122+ return {
123+ ...makeSuccessfulProcess ( JSON . stringify ( result ) ) ,
124+ exitCode : Deferred . await ( finish ) . pipe ( Effect . as ( ChildProcessSpawner . ExitCode ( 0 ) ) ) ,
125+ } ;
126+ } ) ,
127+ ) ;
128+ const target = { alias : "devbox" , hostname : "devbox" , username : null , port : null } ;
129+ const options = runner === "archive" ? ARCHIVE : { nodeScriptPath : "/test/server.js" } ;
130+ const command = Effect . gen ( function * ( ) {
131+ if ( operation === "launch" ) {
132+ const result = yield * SshTunnel . launchOrReuseRemoteServer ( target , undefined , options ) ;
133+ assert . deepEqual ( result , { remotePort : 3774 , remoteServerKind : null } ) ;
134+ } else {
135+ const result = yield * SshTunnel . issueRemotePairingToken ( target , undefined , options ) ;
136+ assert . deepEqual ( result , { credential : "test" } ) ;
137+ }
138+ } ) ;
139+ const fiber = yield * command . pipe (
140+ Effect . provide (
141+ Layer . merge (
142+ NodeServices . layer ,
143+ Layer . succeed ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
144+ ) ,
145+ ) ,
146+ Effect . forkScoped ,
147+ ) ;
148+ yield * Deferred . await ( started ) ;
149+ yield * TestClock . adjust ( Duration . millis ( 900_001 ) ) ;
150+ yield * Deferred . succeed ( finish , undefined ) ;
151+ yield * Fiber . join ( fiber ) ;
152+ } ) . pipe ( Effect . scoped ) ,
153+ ) ;
154+
109155 it . effect ( "accepts launch JSON after remote shell startup noise" , ( ) => {
110156 const target = {
111157 alias : "devbox" ,
@@ -371,7 +417,7 @@ describe("ssh tunnel scripts", () => {
371417// bind unless both sockets set SO_REUSEPORT, so on Linux the preload adds it to
372418// the picker's probe and the holder sets it too.
373419
374- const LOCK_WAIT_SITE = ' if [ "$LOCK_WAIT_COUNT" -ge 200 ]; then' ;
420+ const LOCK_WAIT_SITE = ' if [ "$LOCK_WAIT_COUNT" -ge 9000 ]; then' ;
375421// Gives up after the first failed claim and recovery attempt instead of waiting.
376422const FAIL_FAST : readonly [ string , string ] = [
377423 LOCK_WAIT_SITE ,
@@ -683,6 +729,43 @@ server.listen(Number(flag("--port")), "127.0.0.1", () => {
683729 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
684730 ) ;
685731
732+ it . live ( "waits past the former 20-second limit for a live owner to finish" , ( ) =>
733+ Effect . gen ( function * ( ) {
734+ const { launch, writeVariant } = yield * prepareLaunch ;
735+ const holding = yield * Deferred . make < void > ( ) ;
736+ const releaseHolder = yield * Deferred . make < void > ( ) ;
737+ const holder = yield * writeVariant ( "slow-holder" , [ HOLD_LOCK ] ) ;
738+ const contender = yield * writeVariant ( "patient-contender" , [
739+ [ "LOCK_WAIT_COUNT=0" , "LOCK_WAIT_COUNT=200" ] ,
740+ [ " sleep 0.1" , ' printf "waiting\\n"; read -r release' ] ,
741+ ] ) ;
742+ const first = yield * launch (
743+ "first-alias" ,
744+ {
745+ onLine : ( line ) =>
746+ line === "holding"
747+ ? Deferred . succeed ( holding , undefined ) . pipe ( Effect . asVoid )
748+ : Effect . void ,
749+ release : Deferred . await ( releaseHolder ) ,
750+ } ,
751+ holder ,
752+ ) . pipe ( Effect . forkScoped ) ;
753+ yield * Deferred . await ( holding ) ;
754+ const second = yield * launch (
755+ "second-alias" ,
756+ {
757+ onLine : ( line ) =>
758+ line === "waiting"
759+ ? Deferred . succeed ( releaseHolder , undefined ) . pipe ( Effect . asVoid )
760+ : Effect . void ,
761+ release : Fiber . join ( first ) . pipe ( Effect . orDie , Effect . asVoid ) ,
762+ } ,
763+ contender ,
764+ ) ;
765+ assert . deepEqual ( second , yield * Fiber . join ( first ) ) ;
766+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
767+ ) ;
768+
686769 it . live ( "does not let a late recovery remove the next owner's launch lock" , ( ) =>
687770 Effect . gen ( function * ( ) {
688771 const { fs, run, launch, writeVariant, lockPath, exitedPid } = yield * prepareLaunch ;
0 commit comments