Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/n8n-io/n8n into node-2026-…
Browse files Browse the repository at this point in the history
…community-issue-n8n-form-node-double-pop-up-fix
  • Loading branch information
michael-radency committed Nov 27, 2024
2 parents 2488e14 + 9669380 commit 4d372f0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/cli/src/runners/task-runner-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ export class TaskRunnerServer {
authEndpoint,
send(async (req) => await this.taskRunnerAuthController.createGrantToken(req)),
);

this.app.get('/healthz', (_, res) => res.send({ status: 'ok' }));
}

private handleUpgradeRequest = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('TaskRunnerModule in internal mode', () => {
const runnerConfig = Container.get(TaskRunnersConfig);
runnerConfig.port = 0; // Random port
runnerConfig.mode = 'internal';
runnerConfig.enabled = true;
const module = Container.get(TaskRunnerModule);

afterEach(async () => {
Expand Down
16 changes: 5 additions & 11 deletions packages/cli/test/integration/runners/task-runner-process.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import { TaskRunnersConfig } from '@n8n/config';
import Container from 'typedi';

import { TaskRunnerWsServer } from '@/runners/runner-ws-server';
import { TaskBroker } from '@/runners/task-broker.service';
import { TaskRunnerProcess } from '@/runners/task-runner-process';
import { TaskRunnerServer } from '@/runners/task-runner-server';
import { retryUntil } from '@test-integration/retry-until';
import { setupBrokerTestServer } from '@test-integration/utils/task-broker-test-server';

describe('TaskRunnerProcess', () => {
const authToken = 'token';
const runnerConfig = Container.get(TaskRunnersConfig);
runnerConfig.enabled = true;
runnerConfig.mode = 'internal';
runnerConfig.authToken = authToken;
runnerConfig.port = 0; // Use any port
const taskRunnerServer = Container.get(TaskRunnerServer);

const { config, server: taskRunnerServer } = setupBrokerTestServer({
mode: 'internal',
});
const runnerProcess = Container.get(TaskRunnerProcess);
const taskBroker = Container.get(TaskBroker);
const taskRunnerService = Container.get(TaskRunnerWsServer);

beforeAll(async () => {
await taskRunnerServer.start();
// Set the port to the actually used port
runnerConfig.port = taskRunnerServer.port;
config.port = taskRunnerServer.port;
});

afterAll(async () => {
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/test/integration/runners/task-runner-server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { setupBrokerTestServer } from '@test-integration/utils/task-broker-test-server';

describe('TaskRunnerServer', () => {
const { agent, server } = setupBrokerTestServer({
authToken: 'token',
mode: 'external',
});

beforeAll(async () => {
await server.start();
});

afterAll(async () => {
await server.stop();
});

describe('/healthz', () => {
it('should return 200', async () => {
await agent.get('/healthz').expect(200);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { TaskRunnersConfig } from '@n8n/config';
import request from 'supertest';
import type TestAgent from 'supertest/lib/agent';
import Container from 'typedi';

import { TaskRunnerServer } from '@/runners/task-runner-server';

export interface TestTaskBrokerServer {
server: TaskRunnerServer;
agent: TestAgent;
config: TaskRunnersConfig;
}

/**
* Sets up a Task Broker Server for testing purposes. The server needs
* to be started and stopped manually.
*
* @example
* const { server, agent, config } = setupBrokerTestServer();
*
* beforeAll(async () => await server.start());
* afterAll(async () => await server.stop());
*/
export const setupBrokerTestServer = (
config: Partial<TaskRunnersConfig> = {},
): TestTaskBrokerServer => {
const runnerConfig = Container.get(TaskRunnersConfig);
Object.assign(runnerConfig, config);
runnerConfig.enabled = true;
runnerConfig.port = 0; // Use any port

const taskRunnerServer = Container.get(TaskRunnerServer);
const agent = request.agent(taskRunnerServer.app);

return {
server: taskRunnerServer,
agent,
config: runnerConfig,
};
};

0 comments on commit 4d372f0

Please sign in to comment.