refactor(core): Refactor execution post-execute promises (no-changelog) (#10809)

Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-09-23 12:08:57 +02:00
committed by GitHub
parent 521bbfeee5
commit 67fb6d6fdd
7 changed files with 65 additions and 94 deletions

View File

@@ -94,10 +94,17 @@ describe('ActiveExecutions', () => {
});
test('Should remove an existing execution', async () => {
// ARRANGE
const newExecution = mockExecutionData();
const executionId = await activeExecutions.add(newExecution);
activeExecutions.remove(executionId);
// ACT
activeExecutions.finalizeExecution(executionId);
// Wait until the next tick to ensure that the post-execution promise has settled
await new Promise(setImmediate);
// ASSERT
expect(activeExecutions.getActiveExecutions().length).toBe(0);
});
@@ -110,7 +117,7 @@ describe('ActiveExecutions', () => {
setTimeout(res, 100);
});
const fakeOutput = mockFullRunData();
activeExecutions.remove(executionId, fakeOutput);
activeExecutions.finalizeExecution(executionId, fakeOutput);
await expect(postExecutePromise).resolves.toEqual(fakeOutput);
});
@@ -126,7 +133,7 @@ describe('ActiveExecutions', () => {
const cancellablePromise = mockCancelablePromise();
cancellablePromise.cancel = cancelExecution;
activeExecutions.attachWorkflowExecution(executionId, cancellablePromise);
void activeExecutions.stopExecution(executionId);
activeExecutions.stopExecution(executionId);
expect(cancelExecution).toHaveBeenCalledTimes(1);
});

View File

@@ -1,6 +1,7 @@
import { WorkflowHooks, type ExecutionError, type IWorkflowExecuteHooks } from 'n8n-workflow';
import Container from 'typedi';
import { ActiveExecutions } from '@/active-executions';
import config from '@/config';
import type { User } from '@/databases/entities/user';
import { Telemetry } from '@/telemetry';
@@ -72,6 +73,10 @@ test('processError should process error', async () => {
},
workflow,
);
await Container.get(ActiveExecutions).add(
{ executionMode: 'webhook', workflowData: workflow },
execution.id,
);
config.set('executions.mode', 'regular');
await runner.processError(
new Error('test') as ExecutionError,