fix(core): Fix race condition when resolving post-execute promise (#11360)

This commit is contained in:
Iván Ovejero 2024-10-23 11:56:22 +02:00 committed by GitHub
parent c078a516be
commit 4f1816e03d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View file

@ -108,6 +108,15 @@ describe('ActiveExecutions', () => {
expect(activeExecutions.getActiveExecutions().length).toBe(0);
});
test('Should not try to resolve a post-execute promise for an inactive execution', async () => {
// @ts-expect-error Private method
const getExecutionSpy = jest.spyOn(activeExecutions, 'getExecution');
activeExecutions.finalizeExecution('inactive-execution-id', mockFullRunData());
expect(getExecutionSpy).not.toHaveBeenCalled();
});
test('Should resolve post execute promise on removal', async () => {
const newExecution = mockExecutionData();
const executionId = await activeExecutions.add(newExecution);

View file

@ -154,6 +154,7 @@ export class ActiveExecutions {
/** Resolve the post-execution promise in an execution. */
finalizeExecution(executionId: string, fullRunData?: IRun) {
if (!this.has(executionId)) return;
const execution = this.getExecution(executionId);
execution.postExecutePromise.resolve(fullRunData);
this.logger.debug('Execution finalized', { executionId });