mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
feat(core): Add health check endpoint to task runner server (no-changelog)
This commit is contained in:
parent
0cbb46c8b9
commit
db3b2ce038
|
@ -9,6 +9,38 @@ import { TaskRunnerServer } from '@/runners/task-runner-server';
|
||||||
import type { TaskRunnerServerInitRequest } from '../runner-types';
|
import type { TaskRunnerServerInitRequest } from '../runner-types';
|
||||||
|
|
||||||
describe('TaskRunnerServer', () => {
|
describe('TaskRunnerServer', () => {
|
||||||
|
describe('health endpoint', () => {
|
||||||
|
it('should send 200 status code', async () => {
|
||||||
|
const server = new TaskRunnerServer(
|
||||||
|
mock(),
|
||||||
|
mock<GlobalConfig>({ taskRunners: { path: '/runners' } }),
|
||||||
|
mock(),
|
||||||
|
mock(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const mockResponse = { sendStatus: jest.fn() };
|
||||||
|
|
||||||
|
// @ts-expect-error Test
|
||||||
|
server.app = {
|
||||||
|
get: jest.fn().mockImplementation((path, handler) => {
|
||||||
|
if (path === '/runners/healthz') {
|
||||||
|
handler({}, mockResponse);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
post: jest.fn(),
|
||||||
|
stop: jest.fn().mockResolvedValue(undefined),
|
||||||
|
disable: jest.fn(),
|
||||||
|
use: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
await server.start();
|
||||||
|
|
||||||
|
expect(mockResponse.sendStatus).toHaveBeenCalledWith(200);
|
||||||
|
|
||||||
|
await server.stop(); // allow Jest to exit cleanly
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('handleUpgradeRequest', () => {
|
describe('handleUpgradeRequest', () => {
|
||||||
it('should close WebSocket when response status code is > 200', () => {
|
it('should close WebSocket when response status code is > 200', () => {
|
||||||
const ws = mock<WebSocket>();
|
const ws = mock<WebSocket>();
|
||||||
|
|
|
@ -163,6 +163,9 @@ export class TaskRunnerServer {
|
||||||
authEndpoint,
|
authEndpoint,
|
||||||
send(async (req) => await this.taskRunnerAuthController.createGrantToken(req)),
|
send(async (req) => await this.taskRunnerAuthController.createGrantToken(req)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const healthEndpoint = `${this.getEndpointBasePath()}/healthz`;
|
||||||
|
this.app.get(healthEndpoint, (_, res) => res.sendStatus(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleUpgradeRequest = (
|
private handleUpgradeRequest = (
|
||||||
|
|
Loading…
Reference in a new issue