Skip to content

Commit

Permalink
chore(cli-integ): fix a race condition in the resource-pool tests (#3…
Browse files Browse the repository at this point in the history
…2646)

There was a race condition between `take1` and `take2`, and the tests would expect `take1` to always win the race.

Change the test to force `take1` to win.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Dec 23, 2024
1 parent a0525f5 commit 5aec766
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ const POOL_NAME = 'resource-pool.test';
test('take and dispose', async () => {
const pool = ResourcePool.withResources(POOL_NAME, ['a']);
const take1 = pool.take();
const take2 = pool.take();

let released = false;

const lease1 = await take1;

// We must start the take2 only after take1 has definitely
// succeeded, otherwise we have a race condition if take2 happens to
// win the race (we expect take1 to succeed and take2 to wait).
const take2 = pool.take();

// awaiting 'take2' would now block but we add an async
// handler to it to flip a boolean to see when it gets activated.
void(take2.then(() => released = true));
Expand Down

0 comments on commit 5aec766

Please sign in to comment.