Skip to content

Commit 5aec766

Browse files
authored
chore(cli-integ): fix a race condition in the resource-pool tests (#32646)
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*
1 parent a0525f5 commit 5aec766

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/@aws-cdk-testing/cli-integ/test/resource-pool.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ const POOL_NAME = 'resource-pool.test';
88
test('take and dispose', async () => {
99
const pool = ResourcePool.withResources(POOL_NAME, ['a']);
1010
const take1 = pool.take();
11-
const take2 = pool.take();
1211

1312
let released = false;
1413

1514
const lease1 = await take1;
15+
16+
// We must start the take2 only after take1 has definitely
17+
// succeeded, otherwise we have a race condition if take2 happens to
18+
// win the race (we expect take1 to succeed and take2 to wait).
19+
const take2 = pool.take();
20+
1621
// awaiting 'take2' would now block but we add an async
1722
// handler to it to flip a boolean to see when it gets activated.
1823
void(take2.then(() => released = true));

0 commit comments

Comments
 (0)