diff --git a/packages/cli/src/scaling/__tests__/worker-server.test.ts b/packages/cli/src/scaling/__tests__/worker-server.test.ts index 762842097560e..753a1e3e18468 100644 --- a/packages/cli/src/scaling/__tests__/worker-server.test.ts +++ b/packages/cli/src/scaling/__tests__/worker-server.test.ts @@ -1,10 +1,10 @@ import type { GlobalConfig } from '@n8n/config'; import type express from 'express'; import { mock } from 'jest-mock-extended'; +import type { InstanceSettings } from 'n8n-core'; import { AssertionError } from 'node:assert'; import * as http from 'node:http'; -import config from '@/config'; import { PortTakenError } from '@/errors/port-taken.error'; import type { ExternalHooks } from '@/external-hooks'; import { bodyParser, rawBodyReader } from '@/middlewares'; @@ -27,9 +27,9 @@ describe('WorkerServer', () => { let globalConfig: GlobalConfig; const externalHooks = mock(); + const instanceSettings = mock({ instanceType: 'worker' }); beforeEach(() => { - config.set('generic.instanceType', 'worker'); globalConfig = mock({ queue: { health: { active: true, port: 5678 }, @@ -43,10 +43,16 @@ describe('WorkerServer', () => { describe('constructor', () => { it('should throw if non-worker instance type', () => { - config.set('generic.instanceType', 'webhook'); - expect( - () => new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks), + () => + new WorkerServer( + globalConfig, + mock(), + mock(), + mock(), + externalHooks, + mock({ instanceType: 'webhook' }), + ), ).toThrowError(AssertionError); }); @@ -61,14 +67,15 @@ describe('WorkerServer', () => { }); expect( - () => new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks), + () => + new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks, instanceSettings), ).toThrowError(PortTakenError); }); it('should set up `/healthz` if health check is enabled', async () => { jest.spyOn(http, 'createServer').mockReturnValue(mock()); - new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks); + new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks, instanceSettings); expect(app.get).toHaveBeenCalledWith('/healthz', expect.any(Function)); }); @@ -78,7 +85,7 @@ describe('WorkerServer', () => { jest.spyOn(http, 'createServer').mockReturnValue(mock()); - new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks); + new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks, instanceSettings); expect(app.get).not.toHaveBeenCalled(); }); @@ -89,7 +96,7 @@ describe('WorkerServer', () => { const CREDENTIALS_OVERWRITE_ENDPOINT = 'credentials/overwrites'; globalConfig.credentials.overwrite.endpoint = CREDENTIALS_OVERWRITE_ENDPOINT; - new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks); + new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks, instanceSettings); expect(app.post).toHaveBeenCalledWith( `/${CREDENTIALS_OVERWRITE_ENDPOINT}`, @@ -102,7 +109,7 @@ describe('WorkerServer', () => { it('should not set up `/:endpoint` if overwrites endpoint is not set', async () => { jest.spyOn(http, 'createServer').mockReturnValue(mock()); - new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks); + new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks, instanceSettings); expect(app.post).not.toHaveBeenCalled(); }); @@ -118,7 +125,14 @@ describe('WorkerServer', () => { return server; }); - const workerServer = new WorkerServer(globalConfig, mock(), mock(), mock(), externalHooks); + const workerServer = new WorkerServer( + globalConfig, + mock(), + mock(), + mock(), + externalHooks, + instanceSettings, + ); await workerServer.init(); expect(externalHooks.run).toHaveBeenCalledWith('worker.ready'); diff --git a/packages/cli/src/scaling/worker-server.ts b/packages/cli/src/scaling/worker-server.ts index 2727fa47334e2..cc8d4639514e0 100644 --- a/packages/cli/src/scaling/worker-server.ts +++ b/packages/cli/src/scaling/worker-server.ts @@ -1,12 +1,12 @@ import { GlobalConfig } from '@n8n/config'; import express from 'express'; +import { InstanceSettings } from 'n8n-core'; import { ensureError } from 'n8n-workflow'; import { strict as assert } from 'node:assert'; import http from 'node:http'; import type { Server } from 'node:http'; import { Service } from 'typedi'; -import config from '@/config'; import { CredentialsOverwrites } from '@/credentials-overwrites'; import * as Db from '@/db'; import { CredentialsOverwritesAlreadySetError } from '@/errors/credentials-overwrites-already-set.error'; @@ -40,8 +40,9 @@ export class WorkerServer { private readonly scalingService: ScalingService, private readonly credentialsOverwrites: CredentialsOverwrites, private readonly externalHooks: ExternalHooks, + private readonly instanceSettings: InstanceSettings, ) { - assert(config.getEnv('generic.instanceType') === 'worker'); + assert(this.instanceSettings.instanceType === 'worker'); const app = express();