0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 02:49:32 +01:00
posthog/plugin-server/tests/http-server.test.ts
Brett Hoerner 5b5d0d43a3
chore(plugin-server): make it easier to run multiple plugin-server instances locally (#17456)
* chore(plugin-server): allow customizing the HTTP server port

* chore(plugin-server): add NO_WATCH mode for development

* fix: http-server test
2023-09-15 08:55:46 -06:00

83 lines
2.4 KiB
TypeScript

import http from 'http'
import { DEFAULT_HTTP_SERVER_PORT } from '../src/config/config'
import { startPluginsServer } from '../src/main/pluginsServer'
import { makePiscina } from '../src/worker/piscina'
import { resetTestDatabase } from './helpers/sql'
jest.mock('../src/utils/status')
jest.mock('../src/main/utils', () => {
const actual = jest.requireActual('../src/main/utils')
return {
...actual,
kafkaHealthcheck: async () => {
await Promise.resolve()
return [true, null]
},
}
})
jest.setTimeout(60000) // 60 sec timeout
describe('http server', () => {
// these should simply pass under normal conditions
describe('health and readiness checks', () => {
test('_health', async () => {
const testCode = `
async function processEvent (event) {
return event
}
`
await resetTestDatabase(testCode)
const pluginsServer = await startPluginsServer(
{
WORKER_CONCURRENCY: 0,
},
makePiscina,
{ http: true }
)
await new Promise((resolve) =>
http.get(`http://localhost:${DEFAULT_HTTP_SERVER_PORT}/_health`, (res) => {
const { statusCode } = res
expect(statusCode).toEqual(200)
resolve(null)
})
)
await pluginsServer.stop()
})
test('_ready', async () => {
const testCode = `
async function processEvent (event) {
return event
}
`
await resetTestDatabase(testCode)
const pluginsServer = await startPluginsServer(
{
WORKER_CONCURRENCY: 0,
},
makePiscina,
{ http: true, ingestion: true }
)
await new Promise((resolve) =>
http.get(`http://localhost:${DEFAULT_HTTP_SERVER_PORT}/_ready`, (res) => {
const { statusCode } = res
expect(statusCode).toEqual(200)
resolve(null)
})
)
expect(pluginsServer.queue?.consumerReady).toBeTruthy()
await pluginsServer.stop()
})
})
})