Skip to content

Commit 4cefa6b

Browse files
committed
Log perf test results to Posthog
1 parent b45e208 commit 4cefa6b

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
# Node v22+ needs no strip-types (because we use ts-node for full TS instead)
2727
NODE_OPTIONS: >-
2828
${{ (!startsWith(matrix.node-version, '20') && '--no-experimental-strip-types') || '' }}
29+
# We log performance test results to Posthog to track trends:
30+
POSTHOG_PERF_API_KEY: ${{ secrets.POSTHOG_PERF_API_KEY }}
2931

3032
- name: Deploy docs
3133
if: github.ref == 'refs/heads/main' && matrix.node-version == 'v22.14.0'

test/performance/performance-test-helpers.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,46 @@ export function assertPerformance(
124124
`Errors ${result.errors} exceeds threshold ${thresholds.maxErrors}`
125125
);
126126
}
127-
}
127+
128+
testResults = result;
129+
}
130+
131+
const PERF_LOGGING_API_KEY = process.env.POSTHOG_PERF_API_KEY;
132+
let testResults: PerformanceResult | undefined = undefined;
133+
beforeEach(() => {
134+
testResults = undefined;
135+
});
136+
137+
afterEach(async function () {
138+
if (PERF_LOGGING_API_KEY) {
139+
if (!this.currentTest) throw new Error("Can't log perf results without a test context");
140+
if (this.currentTest.state !== 'passed') return;
141+
if (!testResults) throw new Error("Can't log perf results without test results");
142+
143+
const testTitle = this.currentTest.fullTitle();
144+
145+
const result = await fetch("https://eu.i.posthog.com/capture/", {
146+
method: "POST",
147+
headers: {
148+
"Content-Type": "application/json",
149+
},
150+
body: JSON.stringify({
151+
api_key: PERF_LOGGING_API_KEY,
152+
event: "performance_test_result",
153+
distinct_id: `mockttp-${process.env.ImageOS || 'local'}`,
154+
properties: {
155+
$process_person_profile: false,
156+
sha: process.env.GITHUB_SHA || 'local',
157+
test_name: "Mockttp - " + testTitle,
158+
throughput: testResults.throughput,
159+
mean_latency: testResults.latency.mean,
160+
p99_latency: testResults.latency.p99,
161+
errors: testResults.errors,
162+
163+
},
164+
}),
165+
});
166+
167+
expect(result.ok).to.equal(true, `Failed to log performance results: ${await result.text()}`);
168+
}
169+
});

test/performance/performance-tests.perf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "./performance-test-helpers";
88

99
nodeOnly(() => {
10-
describe("Performance tests", function() {
10+
describe("Performance Tests:", function() {
1111
this.timeout(120000);
1212

1313
describe("Static HTTP mocking", () => {

0 commit comments

Comments
 (0)