@@ -172,29 +172,79 @@ it.effect("bounds Git bursts across drivers without timing out queued commands",
172172 operation : "test.gitBurst" ,
173173 cwd : "/repo" ,
174174 args : [ "rev-parse" , "HEAD" ] ,
175- timeoutMs : index < 4 ? null : 1_000 ,
175+ ... ( index < 4 ? { } : { timeoutMs : index < 8 ? 30_000 : 1_000 } ) ,
176176 } ) ,
177177 { concurrency : "unbounded" } ,
178178 ) . pipe ( Effect . forkChild ) ;
179179
180- yield * Effect . all ( Array . from ( { length : 4 } , ( ) => Queue . take ( starts ) ) ) ;
181180 yield * TestClock . adjust ( "2 seconds" ) ;
182- assert . equal ( yield * Queue . size ( starts ) , 0 ) ;
183- assert . equal ( peak , 4 ) ;
181+ assert . equal ( yield * Queue . size ( starts ) , 8 ) ;
182+ assert . equal ( peak , 8 ) ;
184183 yield * Deferred . succeed ( gate , undefined ) ;
185184 const results = yield * Fiber . join ( burst ) ;
186185 assert . equal ( results . length , 16 ) ;
187186 assert . isTrue ( results . every ( ( result ) => result . stdout === "ok" && result . exitCode === 0 ) ) ;
188- assert . equal ( peak , 4 ) ;
187+ assert . equal ( peak , 8 ) ;
189188 assert . equal ( active , 0 ) ;
190189 const duration = yield * Metric . value (
191190 Metric . withAttributes ( gitCommandDuration , [ [ "operation" , "test.gitBurst" ] ] ) ,
192191 ) ;
193192 assert . equal ( duration . count , 16 ) ;
194- assert . equal ( duration . sum , 8_000 ) ;
193+ assert . equal ( duration . sum , 16_000 ) ;
195194 } ) . pipe ( Effect . provide ( ServerConfigLayer . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
196195) ;
197196
197+ it . effect . each ( [ { timeoutMs : null } , { timeoutMs : 30_001 } ] ) (
198+ "keeps all Git slots available with a pending command whose timeout is $timeoutMs" ,
199+ ( { timeoutMs } ) =>
200+ Effect . gen ( function * ( ) {
201+ const slowGate = yield * Deferred . make < void > ( ) ;
202+ const fastGate = yield * Deferred . make < void > ( ) ;
203+ const starts = yield * Queue . unbounded < void > ( ) ;
204+ let active = 0 ;
205+ const spawner = ChildProcessSpawner . make ( ( command ) =>
206+ Effect . acquireRelease (
207+ Effect . gen ( function * ( ) {
208+ active ++ ;
209+ yield * Queue . offer ( starts , undefined ) ;
210+ const gate =
211+ ChildProcess . isStandardCommand ( command ) && command . args [ 0 ] === "push"
212+ ? slowGate
213+ : fastGate ;
214+ return ChildProcessSpawner . makeHandle ( {
215+ ...makeSuccessfulHandle ( "ok" ) ,
216+ exitCode : Deferred . await ( gate ) . pipe ( Effect . as ( ChildProcessSpawner . ExitCode ( 0 ) ) ) ,
217+ } ) ;
218+ } ) ,
219+ ( ) => Effect . sync ( ( ) => active -- ) ,
220+ ) ,
221+ ) ;
222+ const driver = yield * makeGitVcsDriverCore ( ) . pipe (
223+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
224+ ) ;
225+ const slow = yield * driver
226+ . execute ( { operation : "test.slowGit" , cwd : "/repo" , args : [ "push" ] , timeoutMs } )
227+ . pipe ( Effect . forkChild ) ;
228+ yield * Queue . take ( starts ) ;
229+ const burst = yield * Effect . all (
230+ Array . from ( { length : 8 } , ( ) =>
231+ driver . execute ( { operation : "test.fastGit" , cwd : "/repo" , args : [ "status" ] } ) ,
232+ ) ,
233+ { concurrency : "unbounded" } ,
234+ ) . pipe ( Effect . forkChild ) ;
235+
236+ yield * TestClock . adjust ( "0 seconds" ) ;
237+ assert . equal ( yield * Queue . size ( starts ) , 8 ) ;
238+ assert . equal ( active , 9 ) ;
239+ yield * Deferred . succeed ( fastGate , undefined ) ;
240+ assert . equal ( ( yield * Fiber . join ( burst ) ) . length , 8 ) ;
241+ assert . equal ( active , 1 ) ;
242+ yield * Deferred . succeed ( slowGate , undefined ) ;
243+ assert . equal ( ( yield * Fiber . join ( slow ) ) . stdout , "ok" ) ;
244+ assert . equal ( active , 0 ) ;
245+ } ) . pipe ( Effect . provide ( ServerConfigLayer . pipe ( Layer . provideMerge ( NodeServices . layer ) ) ) ) ,
246+ ) ;
247+
198248for ( const location of [ "root" , "nested" , "worktree" ] as const ) {
199249 it . effect (
200250 `skips clean filters while the ${ location } index is locked and resumes after unlock` ,
0 commit comments