1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-06 09:37:36 +03:00

ci: Fix scaling mode tests (no-changelog) (#10351)

This commit is contained in:
Iván Ovejero 2024-08-12 13:34:37 +02:00 committed by GitHub
parent 5255793afe
commit 021d9981b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,8 @@ import config from '@/config';
import * as BullModule from 'bull'; import * as BullModule from 'bull';
import type { Job, JobData, JobOptions, JobQueue } from '../types'; import type { Job, JobData, JobOptions, JobQueue } from '../types';
import { ApplicationError } from 'n8n-workflow'; import { ApplicationError } from 'n8n-workflow';
import { mockInstance } from '@test/mocking';
import { GlobalConfig } from '@n8n/config';
const queue = mock<JobQueue>({ const queue = mock<JobQueue>({
client: { ping: jest.fn() }, client: { ping: jest.fn() },
@ -16,6 +18,21 @@ jest.mock('bull', () => ({
})); }));
describe('ScalingService', () => { describe('ScalingService', () => {
const globalConfig = mockInstance(GlobalConfig, {
queue: {
bull: {
prefix: 'bull',
redis: {
clusterNodes: '',
host: 'localhost',
password: '',
port: 6379,
tls: false,
},
},
},
});
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks(); jest.clearAllMocks();
config.set('generic.instanceType', 'main'); config.set('generic.instanceType', 'main');
@ -26,8 +43,8 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
const { prefix, settings } = config.get('queue.bull'); const { prefix, settings } = globalConfig.queue.bull;
const Bull = jest.mocked(BullModule.default); const Bull = jest.mocked(BullModule.default);
/** /**
@ -54,7 +71,7 @@ describe('ScalingService', () => {
* Arrange * Arrange
*/ */
config.set('generic.instanceType', 'worker'); config.set('generic.instanceType', 'worker');
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
const concurrency = 5; const concurrency = 5;
@ -73,7 +90,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
/** /**
@ -88,7 +105,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
/** /**
@ -108,7 +125,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
/** /**
@ -128,7 +145,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
queue.add.mockResolvedValue(mock<Job>({ id: '456' })); queue.add.mockResolvedValue(mock<Job>({ id: '456' }));
@ -151,7 +168,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
const jobId = '123'; const jobId = '123';
queue.getJob.mockResolvedValue(mock<Job>({ id: jobId })); queue.getJob.mockResolvedValue(mock<Job>({ id: jobId }));
@ -174,7 +191,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
queue.getJobs.mockResolvedValue([mock<Job>({ id: '123' })]); queue.getJobs.mockResolvedValue([mock<Job>({ id: '123' })]);
@ -195,7 +212,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
// @ts-expect-error - Untyped but possible Redis response // @ts-expect-error - Untyped but possible Redis response
queue.getJobs.mockResolvedValue([mock<Job>(), null]); queue.getJobs.mockResolvedValue([mock<Job>(), null]);
@ -217,7 +234,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
const job = mock<Job>({ isActive: jest.fn().mockResolvedValue(true) }); const job = mock<Job>({ isActive: jest.fn().mockResolvedValue(true) });
@ -237,7 +254,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
const job = mock<Job>({ isActive: jest.fn().mockResolvedValue(false) }); const job = mock<Job>({ isActive: jest.fn().mockResolvedValue(false) });
@ -257,7 +274,7 @@ describe('ScalingService', () => {
/** /**
* Arrange * Arrange
*/ */
const scalingService = new ScalingService(mock(), mock(), mock()); const scalingService = new ScalingService(mock(), mock(), mock(), globalConfig);
await scalingService.setupQueue(); await scalingService.setupQueue();
const job = mock<Job>({ const job = mock<Job>({
isActive: jest.fn().mockImplementation(() => { isActive: jest.fn().mockImplementation(() => {