mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-02 10:46:46 +00:00
The previous test was measuring heap growth while running inside the shared Instance context, which included unrelated tool runtime state that could obscure the actual abort controller leak signal. Now the fetch operations run in a dedicated Bun worker process, giving a clean baseline for memory measurement that accurately reflects whether abort listeners are being properly cleaned up after timed fetches.
50 lines
952 B
TypeScript
50 lines
952 B
TypeScript
import { abortAfterAny } from "../../src/util/abort"
|
|
|
|
const MB = 1024 * 1024
|
|
const ITERATIONS = 50
|
|
|
|
const heap = () => {
|
|
Bun.gc(true)
|
|
return process.memoryUsage().heapUsed / MB
|
|
}
|
|
|
|
const server = Bun.serve({
|
|
port: 0,
|
|
fetch() {
|
|
return new Response("hello from local", {
|
|
headers: {
|
|
"content-type": "text/plain",
|
|
},
|
|
})
|
|
},
|
|
})
|
|
|
|
const url = `http://127.0.0.1:${server.port}`
|
|
|
|
async function run() {
|
|
const { signal, clearTimeout } = abortAfterAny(30000, new AbortController().signal)
|
|
try {
|
|
const response = await fetch(url, { signal })
|
|
await response.text()
|
|
} finally {
|
|
clearTimeout()
|
|
}
|
|
}
|
|
|
|
try {
|
|
await run()
|
|
Bun.sleepSync(100)
|
|
const baseline = heap()
|
|
|
|
for (let i = 0; i < ITERATIONS; i++) {
|
|
await run()
|
|
}
|
|
|
|
Bun.sleepSync(100)
|
|
const after = heap()
|
|
process.stdout.write(JSON.stringify({ baseline, after, growth: after - baseline }))
|
|
} finally {
|
|
server.stop(true)
|
|
process.exit(0)
|
|
}
|