Skip to content

Commit

Permalink
ci: Fix scaling mode tests (no-changelog) (#10351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Aug 12, 2024
1 parent 5255793 commit 021d998
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions packages/cli/src/scaling/__tests__/scaling.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JobQueue>({
client: { ping: jest.fn() },
Expand All @@ -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');
Expand All @@ -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);

/**
Expand All @@ -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;

Expand All @@ -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();

/**
Expand All @@ -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();

/**
Expand All @@ -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();

/**
Expand All @@ -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<Job>({ id: '456' }));

Expand All @@ -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<Job>({ id: jobId }));
Expand All @@ -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<Job>({ id: '123' })]);

Expand All @@ -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<Job>(), null]);
Expand All @@ -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<Job>({ isActive: jest.fn().mockResolvedValue(true) });

Expand All @@ -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<Job>({ isActive: jest.fn().mockResolvedValue(false) });

Expand All @@ -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<Job>({
isActive: jest.fn().mockImplementation(() => {
Expand Down

0 comments on commit 021d998

Please sign in to comment.