1- import { describe , expect , it , beforeEach } from "@effect/vitest" ;
1+ import { describe , expect , it , beforeEach , afterEach , vi } from "@effect/vitest" ;
22
33import {
44 acquireBuildSlot ,
@@ -13,6 +13,10 @@ describe("session-build-semaphore", () => {
1313 resetBuildSlotsForTest ( ) ;
1414 } ) ;
1515
16+ afterEach ( ( ) => {
17+ vi . useRealTimers ( ) ;
18+ } ) ;
19+
1620 it ( "grants up to the cap immediately, with no wait" , async ( ) => {
1721 const results = await Promise . all ( [
1822 acquireBuildSlot ( ) . promise ,
@@ -214,6 +218,7 @@ describe("session-build-semaphore", () => {
214218 } ) ;
215219
216220 it ( "proceeds without a slot when the queue wait exceeds the timeout, and does not count it as active" , async ( ) => {
221+ vi . useFakeTimers ( ) ;
217222 await Promise . all ( [
218223 acquireBuildSlot ( ) . promise ,
219224 acquireBuildSlot ( ) . promise ,
@@ -223,6 +228,10 @@ describe("session-build-semaphore", () => {
223228 expect ( currentActiveBuildsForTest ( ) ) . toBe ( 4 ) ;
224229
225230 const timedOutHandle = acquireBuildSlot ( 10 ) ;
231+ await vi . advanceTimersByTimeAsync ( 9 ) ;
232+ expect ( currentQueueLengthForTest ( ) ) . toBe ( 1 ) ;
233+ expect ( currentActiveBuildsForTest ( ) ) . toBe ( 4 ) ;
234+ await vi . advanceTimersByTimeAsync ( 1 ) ;
226235 const result = await timedOutHandle . promise ;
227236
228237 expect ( result ) . toEqual ( { acquired : false , waitMs : expect . any ( Number ) , timedOut : true } ) ;
0 commit comments