Files
bun.sh/test/js/web/fetch/fetch-leak-test-fixture.js
Jarred Sumner 007f357495 Make readFile() async (#3850)
* less leaky

* async readfile

* Update types.zig

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-07-27 16:55:49 -07:00

35 lines
856 B
JavaScript
Generated

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 || "200", 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);
fetches.length = 0;
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) > 1 + ((COUNT / 2) | 0)) {
throw new Error("Too many Response objects: " + heapStats().objectTypeCounts.Response);
}