mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Move instanceRole to InstanceSettings (no-changelog) (#10242)
This commit is contained in:
committed by
GitHub
parent
7056e50b00
commit
0faf46f4f8
@@ -1,5 +1,5 @@
|
||||
import config from '@/config';
|
||||
import { BinaryDataService } from 'n8n-core';
|
||||
import { BinaryDataService, InstanceSettings } from 'n8n-core';
|
||||
import type { ExecutionStatus } from 'n8n-workflow';
|
||||
import Container from 'typedi';
|
||||
|
||||
@@ -15,10 +15,11 @@ import { mockInstance } from '../shared/mocking';
|
||||
import { createWorkflow } from './shared/db/workflows';
|
||||
import { createExecution, createSuccessfulExecution } from './shared/db/executions';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { OrchestrationService } from '@/services/orchestration.service';
|
||||
|
||||
describe('softDeleteOnPruningCycle()', () => {
|
||||
let pruningService: PruningService;
|
||||
const instanceSettings = new InstanceSettings();
|
||||
instanceSettings.markAsLeader();
|
||||
|
||||
const now = new Date();
|
||||
const yesterday = new Date(Date.now() - TIME.DAY);
|
||||
@@ -29,9 +30,10 @@ describe('softDeleteOnPruningCycle()', () => {
|
||||
|
||||
pruningService = new PruningService(
|
||||
mockInstance(Logger),
|
||||
instanceSettings,
|
||||
Container.get(ExecutionRepository),
|
||||
mockInstance(BinaryDataService),
|
||||
mock<OrchestrationService>(),
|
||||
mock(),
|
||||
);
|
||||
|
||||
workflow = await createWorkflow();
|
||||
|
||||
@@ -10,7 +10,7 @@ jest.useFakeTimers();
|
||||
describe('WaitTracker', () => {
|
||||
const executionRepository = mock<ExecutionRepository>();
|
||||
const multiMainSetup = mock<MultiMainSetup>();
|
||||
const orchestrationService = new OrchestrationService(mock(), mock(), multiMainSetup);
|
||||
const orchestrationService = new OrchestrationService(mock(), mock(), mock(), multiMainSetup);
|
||||
|
||||
const execution = mock<IExecutionResponse>({
|
||||
id: '123',
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import Container from 'typedi';
|
||||
import type Redis from 'ioredis';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
import type { WorkflowActivateMode } from 'n8n-workflow';
|
||||
|
||||
import config from '@/config';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import type { RedisServiceWorkerResponseObject } from '@/services/redis/RedisServiceCommands';
|
||||
@@ -13,11 +18,9 @@ import { Logger } from '@/Logger';
|
||||
import { Push } from '@/push';
|
||||
import { ActiveWorkflowManager } from '@/ActiveWorkflowManager';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
import type { WorkflowActivateMode } from 'n8n-workflow';
|
||||
import { RedisClientService } from '@/services/redis/redis-client.service';
|
||||
import type Redis from 'ioredis';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
|
||||
const instanceSettings = Container.get(InstanceSettings);
|
||||
const redisClientService = mockInstance(RedisClientService);
|
||||
const mockRedisClient = mock<Redis>();
|
||||
redisClientService.createClient.mockReturnValue(mockRedisClient);
|
||||
@@ -72,6 +75,10 @@ describe('Orchestration Service', () => {
|
||||
queueModeId = config.get('redis.queueModeId');
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
instanceSettings.markAsLeader();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
jest.mock('@/services/redis/RedisServicePubSubPublisher').restoreAllMocks();
|
||||
jest.mock('@/services/redis/RedisServicePubSubSubscriber').restoreAllMocks();
|
||||
@@ -141,13 +148,10 @@ describe('Orchestration Service', () => {
|
||||
);
|
||||
expect(helpers.debounceMessageReceiver).toHaveBeenCalledTimes(2);
|
||||
expect(res1!.payload).toBeUndefined();
|
||||
expect((res2!.payload as { result: string }).result).toEqual('debounced');
|
||||
expect(res2!.payload).toEqual({ result: 'debounced' });
|
||||
});
|
||||
|
||||
describe('shouldAddWebhooks', () => {
|
||||
beforeEach(() => {
|
||||
config.set('instanceRole', 'leader');
|
||||
});
|
||||
test('should return true for init', () => {
|
||||
// We want to ensure that webhooks are populated on init
|
||||
// more https://github.com/n8n-io/n8n/pull/8830
|
||||
@@ -169,7 +173,7 @@ describe('Orchestration Service', () => {
|
||||
});
|
||||
|
||||
test('should return false for update or activate when not leader', () => {
|
||||
config.set('instanceRole', 'follower');
|
||||
instanceSettings.markAsFollower();
|
||||
const modes = ['update', 'activate'] as WorkflowActivateMode[];
|
||||
for (const mode of modes) {
|
||||
const result = os.shouldAddWebhooks(mode);
|
||||
|
||||
Reference in New Issue
Block a user