From 5aec766110f65df3a78b3314bc0c30b60c17c2e7 Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Mon, 23 Dec 2024 15:57:37 +0100 Subject: [PATCH] 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* --- .../@aws-cdk-testing/cli-integ/test/resource-pool.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk-testing/cli-integ/test/resource-pool.test.ts b/packages/@aws-cdk-testing/cli-integ/test/resource-pool.test.ts index 7f8bc069fe525..ff5cf3c43a276 100644 --- a/packages/@aws-cdk-testing/cli-integ/test/resource-pool.test.ts +++ b/packages/@aws-cdk-testing/cli-integ/test/resource-pool.test.ts @@ -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));