2024-10-14 07:52:56 -07:00
|
|
|
import { InstanceSettings } from 'n8n-core';
|
|
|
|
import Container from 'typedi';
|
|
|
|
|
2024-08-22 02:10:37 -07:00
|
|
|
import { ActiveWorkflowManager } from '@/active-workflow-manager';
|
2024-08-27 07:44:32 -07:00
|
|
|
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
|
2024-09-12 09:07:18 -07:00
|
|
|
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
|
|
|
import { generateNanoId } from '@/databases/utils/generators';
|
2024-08-28 04:59:27 -07:00
|
|
|
import { MultiMainSetup } from '@/services/orchestration/main/multi-main-setup.ee';
|
2023-12-12 06:18:32 -08:00
|
|
|
|
2024-05-31 00:40:03 -07:00
|
|
|
import { createOwner } from './shared/db/users';
|
2024-09-12 09:07:18 -07:00
|
|
|
import { randomName } from './shared/random';
|
2024-05-31 00:40:03 -07:00
|
|
|
import type { SuperAgentTest } from './shared/types';
|
2024-09-12 09:07:18 -07:00
|
|
|
import { setupTestServer } from './shared/utils';
|
|
|
|
import { mockInstance } from '../shared/mocking';
|
2024-05-31 00:40:03 -07:00
|
|
|
|
2023-12-12 06:18:32 -08:00
|
|
|
describe('DebugController', () => {
|
|
|
|
const workflowRepository = mockInstance(WorkflowRepository);
|
2024-05-06 08:54:05 -07:00
|
|
|
const activeWorkflowManager = mockInstance(ActiveWorkflowManager);
|
2024-10-14 07:52:56 -07:00
|
|
|
const instanceSettings = Container.get(InstanceSettings);
|
|
|
|
instanceSettings.markAsLeader();
|
2023-12-12 06:18:32 -08:00
|
|
|
|
|
|
|
let testServer = setupTestServer({ endpointGroups: ['debug'] });
|
|
|
|
let ownerAgent: SuperAgentTest;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
const owner = await createOwner();
|
|
|
|
ownerAgent = testServer.authAgentFor(owner);
|
|
|
|
testServer.license.enable('feat:multipleMainInstances');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('GET /debug/multi-main-setup', () => {
|
|
|
|
test('should return multi-main setup details', async () => {
|
|
|
|
const workflowId = generateNanoId();
|
2023-12-27 07:55:01 -08:00
|
|
|
const webhooks = [{ id: workflowId, name: randomName() }] as WorkflowEntity[];
|
|
|
|
const triggersAndPollers = [{ id: workflowId, name: randomName() }] as WorkflowEntity[];
|
2023-12-12 06:18:32 -08:00
|
|
|
const activationErrors = { [workflowId]: 'Failed to activate' };
|
2024-10-14 07:52:56 -07:00
|
|
|
const { instanceId } = instanceSettings;
|
2023-12-27 07:55:01 -08:00
|
|
|
const leaderKey = 'some-leader-key';
|
2023-12-12 06:18:32 -08:00
|
|
|
|
2023-12-28 04:14:10 -08:00
|
|
|
workflowRepository.findIn.mockResolvedValue(triggersAndPollers);
|
|
|
|
workflowRepository.findWebhookBasedActiveWorkflows.mockResolvedValue(webhooks);
|
2024-05-06 08:54:05 -07:00
|
|
|
activeWorkflowManager.allActiveInMemory.mockReturnValue([workflowId]);
|
|
|
|
activeWorkflowManager.getAllWorkflowActivationErrors.mockResolvedValue(activationErrors);
|
2023-12-27 07:55:01 -08:00
|
|
|
|
|
|
|
jest.spyOn(MultiMainSetup.prototype, 'fetchLeaderKey').mockResolvedValue(leaderKey);
|
2023-12-12 06:18:32 -08:00
|
|
|
|
|
|
|
const response = await ownerAgent.get('/debug/multi-main-setup').expect(200);
|
|
|
|
|
|
|
|
expect(response.body.data).toMatchObject({
|
|
|
|
instanceId,
|
2023-12-27 07:55:01 -08:00
|
|
|
leaderKey,
|
|
|
|
isLeader: true,
|
|
|
|
activeWorkflows: {
|
|
|
|
webhooks,
|
|
|
|
triggersAndPollers,
|
|
|
|
},
|
2023-12-12 06:18:32 -08:00
|
|
|
activationErrors,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|