2021-03-22 12:39:24 +01:00
|
|
|
import { startPluginsServer } from '../../src/main/pluginsServer'
|
2021-05-25 13:49:41 +02:00
|
|
|
import { Hub, LogLevel } from '../../src/types'
|
2021-05-03 13:14:30 +02:00
|
|
|
import { UUIDT } from '../../src/utils/utils'
|
2021-02-18 08:52:25 +01:00
|
|
|
import { makePiscina } from '../../src/worker/piscina'
|
2021-03-22 12:39:24 +01:00
|
|
|
import { createPosthog, DummyPostHog } from '../../src/worker/vm/extensions/posthog'
|
2021-02-18 08:52:25 +01:00
|
|
|
import { pluginConfig39 } from '../helpers/plugins'
|
|
|
|
import { resetTestDatabase } from '../helpers/sql'
|
|
|
|
import { delayUntilEventIngested } from '../shared/process-event'
|
|
|
|
|
|
|
|
jest.setTimeout(60000) // 60 sec timeout
|
|
|
|
|
|
|
|
describe('e2e postgres ingestion timeout', () => {
|
2021-05-25 13:49:41 +02:00
|
|
|
let hub: Hub
|
2021-02-18 08:52:25 +01:00
|
|
|
let stopServer: () => Promise<void>
|
|
|
|
let posthog: DummyPostHog
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await resetTestDatabase(`
|
|
|
|
async function processEvent (event) {
|
|
|
|
await new Promise(resolve => __jestSetTimeout(() => resolve(), 800))
|
|
|
|
await new Promise(resolve => __jestSetTimeout(() => resolve(), 800))
|
|
|
|
await new Promise(resolve => __jestSetTimeout(() => resolve(), 800))
|
|
|
|
await new Promise(resolve => __jestSetTimeout(() => resolve(), 800))
|
|
|
|
await new Promise(resolve => __jestSetTimeout(() => resolve(), 800))
|
|
|
|
event.properties = { passed: true }
|
|
|
|
return event
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
const startResponse = await startPluginsServer(
|
|
|
|
{
|
|
|
|
WORKER_CONCURRENCY: 2,
|
|
|
|
TASK_TIMEOUT: 2,
|
|
|
|
PLUGINS_CELERY_QUEUE: 'test-plugins-celery-queue',
|
|
|
|
CELERY_DEFAULT_QUEUE: 'test-celery-default-queue',
|
|
|
|
LOG_LEVEL: LogLevel.Log,
|
|
|
|
KAFKA_ENABLED: false,
|
|
|
|
},
|
|
|
|
makePiscina
|
|
|
|
)
|
2021-05-25 13:49:41 +02:00
|
|
|
hub = startResponse.hub
|
2021-02-18 08:52:25 +01:00
|
|
|
stopServer = startResponse.stop
|
2021-05-25 13:49:41 +02:00
|
|
|
const redis = await hub.redisPool.acquire()
|
|
|
|
await redis.del(hub.PLUGINS_CELERY_QUEUE)
|
|
|
|
await redis.del(hub.CELERY_DEFAULT_QUEUE)
|
|
|
|
await hub.redisPool.release(redis)
|
2021-02-18 08:52:25 +01:00
|
|
|
|
2021-05-25 13:49:41 +02:00
|
|
|
posthog = createPosthog(hub, pluginConfig39)
|
2021-02-18 08:52:25 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await stopServer()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('event captured, processed, ingested', async () => {
|
2021-05-25 13:49:41 +02:00
|
|
|
expect((await hub.db.fetchEvents()).length).toBe(0)
|
2021-02-18 08:52:25 +01:00
|
|
|
const uuid = new UUIDT().toString()
|
2021-08-27 17:53:31 +02:00
|
|
|
await posthog.capture('custom event', { name: 'haha', uuid, randomProperty: 'lololo' })
|
2021-05-25 13:49:41 +02:00
|
|
|
await delayUntilEventIngested(() => hub.db.fetchEvents())
|
|
|
|
const events = await hub.db.fetchEvents()
|
2021-02-18 08:52:25 +01:00
|
|
|
expect(events.length).toBe(1)
|
|
|
|
expect(events[0].properties.name).toEqual('haha')
|
|
|
|
expect(events[0].properties.passed).not.toEqual(true)
|
|
|
|
})
|
|
|
|
})
|