forked from PostHog/posthog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp-server.test.ts
82 lines (69 loc) · 2.37 KB
/
http-server.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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()
})
})
})