From 1c768b719970fb049875abd262245f0af33b7d5a Mon Sep 17 00:00:00 2001 From: Danny Martini Date: Tue, 17 Sep 2024 23:12:59 +0200 Subject: [PATCH] fix remaining test --- .../cli/src/__tests__/active-executions.test.ts | 9 +++++++++ packages/cli/src/active-executions.ts | 16 ++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/__tests__/active-executions.test.ts b/packages/cli/src/__tests__/active-executions.test.ts index 8c4943dd99..14bc182525 100644 --- a/packages/cli/src/__tests__/active-executions.test.ts +++ b/packages/cli/src/__tests__/active-executions.test.ts @@ -94,10 +94,19 @@ describe('ActiveExecutions', () => { }); test('Should remove an existing execution', async () => { + // ARRANGE const newExecution = mockExecutionData(); const executionId = await activeExecutions.add(newExecution); + + // ACT activeExecutions.finishExecution(executionId); + // TODO: Wait 2 ticks. This will be unnecessary once the `setImmediate` in + // `active-executions` is removed. + await new Promise((resolve) => setImmediate(resolve)); + await new Promise((resolve) => setImmediate(resolve)); + + // ASSERT expect(activeExecutions.getActiveExecutions().length).toBe(0); }); diff --git a/packages/cli/src/active-executions.ts b/packages/cli/src/active-executions.ts index 95286889f6..775b2a6a10 100644 --- a/packages/cli/src/active-executions.ts +++ b/packages/cli/src/active-executions.ts @@ -106,12 +106,16 @@ export class ActiveExecutions { }; // Automatically remove execution once the postExecutePromise settles - void postExecutePromise.promise.finally(() => { - this.concurrencyControl.release({ mode: executionData.executionMode }); - setImmediate(() => { - delete this.activeExecutions[executionId]; - }); - }); + void postExecutePromise.promise + .finally(() => { + this.concurrencyControl.release({ mode: executionData.executionMode }); + setImmediate(() => { + delete this.activeExecutions[executionId]; + }); + }) + // Attach a no-op handler to prevent an unhandled rejection, because + // finally will not handle it, but rather rethrow it. + .catch(() => {}); return executionId; }