forked from PostHog/posthog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.test.ts
177 lines (154 loc) · 5.43 KB
/
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import * as Sentry from '@sentry/node'
import * as nodeSchedule from 'node-schedule'
import { startGraphileWorker } from '../src/main/graphile-worker/worker-setup'
import { ServerInstance, startPluginsServer } from '../src/main/pluginsServer'
import { LogLevel, PluginServerCapabilities, PluginsServerConfig } from '../src/types'
import { makePiscina } from '../src/worker/piscina'
import { resetTestDatabase } from './helpers/sql'
jest.mock('../src/utils/kill')
jest.mock('../src/main/graphile-worker/schedule')
jest.mock('../src/main/graphile-worker/worker-setup')
jest.setTimeout(20000) // 20 sec timeout - longer indicates an issue
function numberOfScheduledJobs() {
return Object.keys(nodeSchedule.scheduledJobs).length
}
describe('server', () => {
let pluginsServer: Partial<ServerInstance> | null = null
function createPluginServer(config: Partial<PluginsServerConfig>, capabilities: PluginServerCapabilities) {
return startPluginsServer(
{
WORKER_CONCURRENCY: 2,
LOG_LEVEL: LogLevel.Debug,
...config,
},
makePiscina,
capabilities
)
}
beforeEach(() => {
jest.spyOn(Sentry, 'captureMessage')
})
afterEach(async () => {
await pluginsServer?.stop?.()
pluginsServer = null
})
// Running all capabilities together takes too long in tests, so they are split up
test('startPluginsServer does not error - ingestion', async () => {
const testCode = `
async function processEvent (event) {
return event
}
`
await resetTestDatabase(testCode)
pluginsServer = await createPluginServer(
{},
{
http: true,
mmdb: true,
ingestion: true,
ingestionOverflow: true,
ingestionHistorical: true,
appManagementSingleton: true,
preflightSchedules: true,
}
)
})
test('startPluginsServer does not error - pipelines', async () => {
const testCode = `
async function processEvent (event) {
return event
}
`
await resetTestDatabase(testCode)
pluginsServer = await createPluginServer(
{},
{
http: true,
eventsIngestionPipelines: true,
}
)
})
test('startPluginsServer does not error - cdp', async () => {
const testCode = `
async function processEvent (event) {
return event
}
`
await resetTestDatabase(testCode)
pluginsServer = await createPluginServer(
{},
{
http: true,
pluginScheduledTasks: true,
processPluginJobs: true,
processAsyncOnEventHandlers: true,
processAsyncWebhooksHandlers: true,
cdpProcessedEvents: true,
cdpFunctionCallbacks: true,
cdpFunctionOverflow: true,
}
)
})
test('startPluginsServer does not error - replay', async () => {
const testCode = `
async function processEvent (event) {
return event
}
`
await resetTestDatabase(testCode)
pluginsServer = await createPluginServer(
{},
{
http: true,
sessionRecordingBlobIngestion: true,
sessionRecordingBlobOverflowIngestion: true,
}
)
})
test('starting and stopping node-schedule scheduled jobs', async () => {
expect(numberOfScheduledJobs()).toEqual(0)
pluginsServer = await createPluginServer(
{},
{
http: true,
pluginScheduledTasks: true,
processAsyncWebhooksHandlers: true,
preflightSchedules: true,
}
)
expect(numberOfScheduledJobs()).toBeGreaterThan(1)
await pluginsServer.stop?.()
pluginsServer = null
expect(numberOfScheduledJobs()).toEqual(0)
})
describe('plugin-server capabilities', () => {
test('starts graphile for scheduled tasks capability', async () => {
pluginsServer = await createPluginServer(
{},
{ ingestion: true, pluginScheduledTasks: true, processPluginJobs: true }
)
expect(startGraphileWorker).toHaveBeenCalled()
})
test('disabling pluginScheduledTasks', async () => {
pluginsServer = await createPluginServer(
{},
{ ingestion: true, pluginScheduledTasks: false, processPluginJobs: true }
)
expect(startGraphileWorker).toHaveBeenCalled()
})
test('disabling processPluginJobs', async () => {
pluginsServer = await createPluginServer(
{},
{ ingestion: true, pluginScheduledTasks: true, processPluginJobs: false }
)
expect(startGraphileWorker).toHaveBeenCalled()
})
test('disabling processPluginJobs, ingestion, and pluginScheduledTasks', async () => {
pluginsServer = await createPluginServer(
{},
{ ingestion: false, pluginScheduledTasks: false, processPluginJobs: false }
)
expect(startGraphileWorker).not.toHaveBeenCalled()
})
})
})