Skip to content

Commit

Permalink
Add failing test for crowd-out condition
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurvihill committed Feb 2, 2024
1 parent 6af938b commit 6a55acb
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/semaphoreSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ export const semaphoreSuite = (factory: (maxConcurrency: number, err?: Error) =>
assert.deepStrictEqual(values.sort(), [2, 2]);
});

test('acquire allows light items to run eventually', async () => {
let done = false;
async function lightLoop() {
while (!done) {
const [,release] = await semaphore.acquire(1);
await new Promise((resolve) => { setTimeout(resolve, 10); });
release();
}
}
lightLoop();
await clock.tickAsync(5);
lightLoop();
semaphore.acquire(2).then(() => { done = true; });
await clock.tickAsync(10);
await clock.tickAsync(10);
assert.strictEqual(done, true);
});

test('acquire blocks when the semaphore has reached zero until it is released again', async () => {
const values: Array<number> = [];

Expand Down

0 comments on commit 6a55acb

Please sign in to comment.