diff options
Diffstat (limited to 'test/js/web/fetch/fetch-leak-test-fixture.js')
-rw-r--r-- | test/js/web/fetch/fetch-leak-test-fixture.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/js/web/fetch/fetch-leak-test-fixture.js b/test/js/web/fetch/fetch-leak-test-fixture.js new file mode 100644 index 000000000..07275a425 --- /dev/null +++ b/test/js/web/fetch/fetch-leak-test-fixture.js @@ -0,0 +1,34 @@ +import { heapStats } from "bun:jsc"; + +const { SERVER } = process.env; + +if (typeof SERVER === "undefined" || !SERVER?.length) { + throw new Error("SERVER environment variable is not set"); +} + +const COUNT = parseInt(process.env.COUNT || "50", 10); +await (async function runAll() { + var fetches = new Array(COUNT); + let i = 0; + while (i < Math.max(COUNT - 32, 0)) { + for (let j = 0; j < 32; j++) { + fetches.push(fetch(SERVER)); + } + await Promise.all(fetches.slice(i, i + 32)); + i += 32; + } + + while (i++ < COUNT) { + fetches.push(fetch(SERVER)); + } + + await Promise.all(fetches); + fetches.length = 0; + fetches = []; +})(); +await Bun.sleep(10); +Bun.gc(true); + +if ((heapStats().objectTypeCounts.Response ?? 0) > 10) { + throw new Error("Too many Response objects: " + heapStats().objectTypeCounts.Response); +} |