fix remaining test

This commit is contained in:
Danny Martini 2024-09-17 23:12:59 +02:00
parent c7ed0485f9
commit 1c768b7199
No known key found for this signature in database
2 changed files with 19 additions and 6 deletions

View file

@ -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);
});

View file

@ -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;
}