mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-28 05:59:42 -08:00
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import type { User } from '@db/entities/User';
|
|
import * as testDb from '../integration/shared/testDb';
|
|
import * as utils from '../integration/shared/utils/';
|
|
import { createWorkflow, createExecution } from '../integration/shared/testDb';
|
|
import { WorkflowRunner } from '@/WorkflowRunner';
|
|
import { WorkflowHooks, type ExecutionError, type IWorkflowExecuteHooks } from 'n8n-workflow';
|
|
import { Push } from '@/push';
|
|
import { mockInstance } from '../integration/shared/utils';
|
|
import Container from 'typedi';
|
|
import config from '@/config';
|
|
|
|
let owner: User;
|
|
let runner: WorkflowRunner;
|
|
let hookFunctions: IWorkflowExecuteHooks;
|
|
utils.setupTestServer({ endpointGroups: [] });
|
|
|
|
class Watchers {
|
|
workflowExecuteAfter = jest.fn();
|
|
}
|
|
const watchers = new Watchers();
|
|
const watchedWorkflowExecuteAfter = jest.spyOn(watchers, 'workflowExecuteAfter');
|
|
|
|
beforeAll(async () => {
|
|
const globalOwnerRole = await testDb.getGlobalOwnerRole();
|
|
owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
|
|
|
mockInstance(Push);
|
|
Container.set(Push, new Push());
|
|
|
|
runner = new WorkflowRunner();
|
|
|
|
hookFunctions = {
|
|
workflowExecuteAfter: [watchers.workflowExecuteAfter],
|
|
};
|
|
});
|
|
|
|
afterAll(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await testDb.truncate(['Workflow', 'SharedWorkflow']);
|
|
});
|
|
|
|
test('processError should return early in Bull stalled edge case', async () => {
|
|
const workflow = await createWorkflow({}, owner);
|
|
const execution = await createExecution(
|
|
{
|
|
status: 'success',
|
|
finished: true,
|
|
},
|
|
workflow,
|
|
);
|
|
config.set('executions.mode', 'queue');
|
|
await runner.processError(
|
|
new Error('test') as ExecutionError,
|
|
new Date(),
|
|
'webhook',
|
|
execution.id,
|
|
new WorkflowHooks(hookFunctions, 'webhook', execution.id, workflow),
|
|
);
|
|
expect(watchedWorkflowExecuteAfter).toHaveBeenCalledTimes(0);
|
|
});
|
|
|
|
test('processError should process error', async () => {
|
|
const workflow = await createWorkflow({}, owner);
|
|
const execution = await createExecution(
|
|
{
|
|
status: 'success',
|
|
finished: true,
|
|
},
|
|
workflow,
|
|
);
|
|
config.set('executions.mode', 'regular');
|
|
await runner.processError(
|
|
new Error('test') as ExecutionError,
|
|
new Date(),
|
|
'webhook',
|
|
execution.id,
|
|
new WorkflowHooks(hookFunctions, 'webhook', execution.id, workflow),
|
|
);
|
|
expect(watchedWorkflowExecuteAfter).toHaveBeenCalledTimes(1);
|
|
});
|