Skip to content

Commit 18b0e5c

Browse files
committed
fix(bench): include autocannon failures in request totals
1 parent 09c519f commit 18b0e5c

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

bench/routing/drivers.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@ describe('oha command', () => {
5454
})
5555

5656
describe('autocannon load isolation', () => {
57+
it.each([
58+
['transport failures only', 0, 20, 0, 0, 20, 20],
59+
['mixed responses and failures', 90, 10, 10, 3, 100, 20],
60+
['responses without failures', 20, undefined, undefined, undefined, 20, 0],
61+
] as const)('counts every completed or failed request: %s', async (name, completed, transportErrors, non2xx, timeouts, requests, errors) => {
62+
const raw = JSON.stringify({ requests: { total: completed }, errors: transportErrors, non2xx, timeouts })
63+
const spawn = spyOn(Bun, 'spawn').mockReturnValue({
64+
stdout: new Response(raw).body,
65+
stderr: new Response('').body,
66+
exited: Promise.resolve(0),
67+
} as unknown as ReturnType<typeof Bun.spawn>)
68+
try {
69+
const result = await DRIVERS.find(driver => driver.name === 'autocannon')!.run({
70+
url: 'http://127.0.0.1:39400/bench/json',
71+
method: 'GET',
72+
headers: {},
73+
connections: 1,
74+
warmupSeconds: 0,
75+
durationSeconds: 1,
76+
})
77+
expect(result.requests, name).toBe(requests)
78+
expect(result.errors, name).toBe(errors)
79+
expect(result.raw).toBe(raw)
80+
}
81+
finally {
82+
spawn.mockRestore()
83+
}
84+
})
85+
5786
it.each([0, 3])('discards %s seconds of warmup with isolated load settings', async (warmupSeconds) => {
5887
const output = (requests: number) => ({
5988
stdout: new Response(JSON.stringify({ requests: { total: requests, average: requests } })).body,

bench/routing/drivers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ const autocannon: Driver = {
193193
p90: json.latency?.p90 ?? 0,
194194
p99: json.latency?.p99 ?? 0,
195195
},
196-
requests: json.requests?.total ?? 0,
196+
// Autocannon's total counts HTTP responses only. Its errors already
197+
// include timeouts, so add that count once to include failed attempts.
198+
requests: (json.requests?.total ?? 0) + (json.errors ?? 0),
197199
errors: (json.errors ?? 0) + (json.non2xx ?? 0),
198200
raw,
199201
}

0 commit comments

Comments
 (0)