diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43dd50f5..90c40a50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,3 +51,9 @@ jobs: DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres' REDIS_URL: 'redis://localhost' run: yarn task:db-init && yarn test + + - name: Run benchmarks + env: + DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres' + REDIS_URL: 'redis://localhost' + run: yarn task:db-init && yarn benchmark diff --git a/tests/worker.test.ts b/benchmarks/worker.benchmark.ts similarity index 97% rename from tests/worker.test.ts rename to benchmarks/worker.benchmark.ts index 5df88d36..d73ff48f 100644 --- a/tests/worker.test.ts +++ b/benchmarks/worker.benchmark.ts @@ -2,7 +2,7 @@ import { makePiscina } from '../src/worker/piscina' import { defaultConfig } from '../src/config' import { PluginEvent } from 'posthog-plugins/src/types' import { performance } from 'perf_hooks' -import { mockJestWithIndex } from './helpers/plugins' +import { mockJestWithIndex } from '../tests/helpers/plugins' import * as os from 'os' import { LogLevel } from '../src/types' @@ -71,7 +71,7 @@ function setupPiscina(workers: number, code: string, tasksPerWorker: number) { }) } -test('piscina worker test', async () => { +test('piscina worker benchmark', async () => { // Uncomment this to become a 10x developer and make the test run just as fast! // Reduces events by 10x and limits threads to max 8 for quicker development const isLightDevRun = false diff --git a/jest.config.js b/jest.config.js index 6dcc4105..c7b202e5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,5 +4,5 @@ module.exports = { clearMocks: true, coverageProvider: 'v8', setupFilesAfterEnv: ['./jest.setup.pg-mock.js', './jest.setup.redis-mock.js', './jest.setup.fetch-mock.js'], - testMatch: ['/tests/**/*.test.ts'], + testMatch: ['/tests/**/*.test.ts', '/benchmarks/**/*.benchmark.ts'], } diff --git a/package.json b/package.json index 74bf706f..bd84941b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "types": "dist/src/index.d.ts", "main": "dist/src/index.js", "scripts": { - "test": "jest --runInBand", + "test": "jest --testPathIgnorePatterns='benchmarks/'", + "benchmark": "jest --runInBand benchmarks/", "start": "yarn start:dev", "start:dist": "node dist/src/index.js --base-dir ../posthog", "start:dev": "ts-node-dev --exit-child src/index.ts --base-dir ../posthog",