2023-09-07 05:44:19 -07:00
|
|
|
import { Worker } from '@/commands/worker';
|
|
|
|
import * as Config from '@oclif/config';
|
2023-09-26 04:58:06 -07:00
|
|
|
import config from '@/config';
|
2023-09-07 05:44:19 -07:00
|
|
|
import { Telemetry } from '@/telemetry';
|
|
|
|
import { ExternalSecretsManager } from '@/ExternalSecrets/ExternalSecretsManager.ee';
|
2023-09-22 08:22:12 -07:00
|
|
|
import { BinaryDataService } from 'n8n-core';
|
2023-09-07 05:44:19 -07:00
|
|
|
import { CacheService } from '@/services/cache.service';
|
|
|
|
import { RedisServicePubSubPublisher } from '@/services/redis/RedisServicePubSubPublisher';
|
|
|
|
import { RedisServicePubSubSubscriber } from '@/services/redis/RedisServicePubSubSubscriber';
|
|
|
|
import { MessageEventBus } from '@/eventbus/MessageEventBus/MessageEventBus';
|
|
|
|
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
|
|
|
import { CredentialTypes } from '@/CredentialTypes';
|
|
|
|
import { NodeTypes } from '@/NodeTypes';
|
|
|
|
import { InternalHooks } from '@/InternalHooks';
|
|
|
|
import { PostHogClient } from '@/posthog';
|
|
|
|
import { RedisService } from '@/services/redis.service';
|
2023-10-06 04:58:11 -07:00
|
|
|
import { OrchestrationHandlerWorkerService } from '@/services/orchestration/worker/orchestration.handler.worker.service';
|
|
|
|
import { OrchestrationWorkerService } from '@/services/orchestration/worker/orchestration.worker.service';
|
2023-11-17 06:58:50 -08:00
|
|
|
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
2023-09-07 05:44:19 -07:00
|
|
|
|
2023-11-10 06:04:26 -08:00
|
|
|
import { mockInstance } from '../../shared/mocking';
|
|
|
|
|
2023-09-26 04:58:06 -07:00
|
|
|
const oclifConfig: Config.IConfig = new Config.Config({ root: __dirname });
|
2023-09-07 05:44:19 -07:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2023-09-26 04:58:06 -07:00
|
|
|
config.set('executions.mode', 'queue');
|
2023-10-05 06:25:17 -07:00
|
|
|
config.set('binaryDataManager.availableModes', 'filesystem');
|
2023-09-07 05:44:19 -07:00
|
|
|
mockInstance(Telemetry);
|
|
|
|
mockInstance(PostHogClient);
|
|
|
|
mockInstance(InternalHooks);
|
|
|
|
mockInstance(CacheService);
|
|
|
|
mockInstance(ExternalSecretsManager);
|
2023-09-22 08:22:12 -07:00
|
|
|
mockInstance(BinaryDataService);
|
2023-09-07 05:44:19 -07:00
|
|
|
mockInstance(MessageEventBus);
|
|
|
|
mockInstance(LoadNodesAndCredentials);
|
|
|
|
mockInstance(CredentialTypes);
|
|
|
|
mockInstance(NodeTypes);
|
|
|
|
mockInstance(RedisService);
|
|
|
|
mockInstance(RedisServicePubSubPublisher);
|
|
|
|
mockInstance(RedisServicePubSubSubscriber);
|
2023-11-17 06:58:50 -08:00
|
|
|
mockInstance(MultiMainSetup);
|
2023-09-07 05:44:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('worker initializes all its components', async () => {
|
2023-09-26 04:58:06 -07:00
|
|
|
const worker = new Worker([], oclifConfig);
|
2023-09-07 05:44:19 -07:00
|
|
|
|
|
|
|
jest.spyOn(worker, 'init');
|
|
|
|
jest.spyOn(worker, 'initLicense').mockImplementation(async () => {});
|
2023-09-22 08:22:12 -07:00
|
|
|
jest.spyOn(worker, 'initBinaryDataService').mockImplementation(async () => {});
|
2023-09-07 05:44:19 -07:00
|
|
|
jest.spyOn(worker, 'initExternalHooks').mockImplementation(async () => {});
|
|
|
|
jest.spyOn(worker, 'initExternalSecrets').mockImplementation(async () => {});
|
|
|
|
jest.spyOn(worker, 'initEventBus').mockImplementation(async () => {});
|
2023-10-06 04:58:11 -07:00
|
|
|
jest.spyOn(worker, 'initOrchestration');
|
2023-09-07 05:44:19 -07:00
|
|
|
jest
|
2023-10-06 04:58:11 -07:00
|
|
|
.spyOn(OrchestrationWorkerService.prototype, 'publishToEventLog')
|
2023-09-07 05:44:19 -07:00
|
|
|
.mockImplementation(async () => {});
|
|
|
|
jest
|
2023-10-06 04:58:11 -07:00
|
|
|
.spyOn(OrchestrationHandlerWorkerService.prototype, 'initSubscriber')
|
2023-09-07 05:44:19 -07:00
|
|
|
.mockImplementation(async () => {});
|
2023-10-06 04:58:11 -07:00
|
|
|
jest.spyOn(RedisServicePubSubPublisher.prototype, 'init').mockImplementation(async () => {});
|
2023-09-07 05:44:19 -07:00
|
|
|
jest.spyOn(worker, 'initQueue').mockImplementation(async () => {});
|
|
|
|
|
|
|
|
await worker.init();
|
|
|
|
|
2023-09-26 04:58:06 -07:00
|
|
|
expect(worker.queueModeId).toBeDefined();
|
|
|
|
expect(worker.queueModeId).toContain('worker');
|
|
|
|
expect(worker.queueModeId.length).toBeGreaterThan(15);
|
2023-12-14 07:16:12 -08:00
|
|
|
expect(worker.initLicense).toHaveBeenCalledTimes(1);
|
|
|
|
expect(worker.initBinaryDataService).toHaveBeenCalledTimes(1);
|
|
|
|
expect(worker.initExternalHooks).toHaveBeenCalledTimes(1);
|
|
|
|
expect(worker.initExternalSecrets).toHaveBeenCalledTimes(1);
|
|
|
|
expect(worker.initEventBus).toHaveBeenCalledTimes(1);
|
|
|
|
expect(worker.initOrchestration).toHaveBeenCalledTimes(1);
|
|
|
|
expect(OrchestrationHandlerWorkerService.prototype.initSubscriber).toHaveBeenCalledTimes(1);
|
|
|
|
expect(OrchestrationWorkerService.prototype.publishToEventLog).toHaveBeenCalledTimes(1);
|
|
|
|
expect(worker.initQueue).toHaveBeenCalledTimes(1);
|
2023-09-07 05:44:19 -07:00
|
|
|
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
});
|