From 021d9981b6c089ab2b7123e4aa07eeba9d06ec86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Mon, 12 Aug 2024 13:34:37 +0200 Subject: [PATCH] ci: Fix scaling mode tests (no-changelog) (#10351) --- .../scaling/__tests__/scaling.service.test.ts | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/scaling/__tests__/scaling.service.test.ts b/packages/cli/src/scaling/__tests__/scaling.service.test.ts index 0a798fae3e..6883a96ffd 100644 --- a/packages/cli/src/scaling/__tests__/scaling.service.test.ts +++ b/packages/cli/src/scaling/__tests__/scaling.service.test.ts @@ -5,6 +5,8 @@ import config from '@/config'; import * as BullModule from 'bull'; import type { Job, JobData, JobOptions, JobQueue } from '../types'; import { ApplicationError } from 'n8n-workflow'; +import { mockInstance } from '@test/mocking'; +import { GlobalConfig } from '@n8n/config'; const queue = mock({ client: { ping: jest.fn() }, @@ -16,6 +18,21 @@ jest.mock('bull', () => ({ })); describe('ScalingService', () => { + const globalConfig = mockInstance(GlobalConfig, { + queue: { + bull: { + prefix: 'bull', + redis: { + clusterNodes: '', + host: 'localhost', + password: '', + port: 6379, + tls: false, + }, + }, + }, + }); + beforeEach(() => { jest.clearAllMocks(); config.set('generic.instanceType', 'main'); @@ -26,8 +43,8 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); - const { prefix, settings } = config.get('queue.bull'); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); + const { prefix, settings } = globalConfig.queue.bull; const Bull = jest.mocked(BullModule.default); /** @@ -54,7 +71,7 @@ describe('ScalingService', () => { * Arrange */ config.set('generic.instanceType', 'worker'); - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); const concurrency = 5; @@ -73,7 +90,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); /** @@ -88,7 +105,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); /** @@ -108,7 +125,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); /** @@ -128,7 +145,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); queue.add.mockResolvedValue(mock({ id: '456' })); @@ -151,7 +168,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); const jobId = '123'; queue.getJob.mockResolvedValue(mock({ id: jobId })); @@ -174,7 +191,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); queue.getJobs.mockResolvedValue([mock({ id: '123' })]); @@ -195,7 +212,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); // @ts-expect-error - Untyped but possible Redis response queue.getJobs.mockResolvedValue([mock(), null]); @@ -217,7 +234,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); const job = mock({ isActive: jest.fn().mockResolvedValue(true) }); @@ -237,7 +254,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); const job = mock({ isActive: jest.fn().mockResolvedValue(false) }); @@ -257,7 +274,7 @@ describe('ScalingService', () => { /** * Arrange */ - const scalingService = new ScalingService(mock(), mock(), mock()); + const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig); await scalingService.setupQueue(); const job = mock({ isActive: jest.fn().mockImplementation(() => {