Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed May 1, 2024
1 parent 0f39522 commit fdbe9e2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/js/bun/http/serve-body-leak.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { bunExe, bunEnv } from "harness";
import type { Subprocess } from "bun";

const ACCEPTABLE_MEMORY_LEAK = 2; //MB for acceptable memory leak variance
const payload = "1".repeat(64 * 1024); // decent size payload to test memory leak
const payload = "1".repeat(32 * 1024); // decent size payload to test memory leak

let url: URL;
let process: Subprocess<"ignore", "pipe", "inherit"> | null = null;
Expand Down Expand Up @@ -32,20 +32,24 @@ async function warmup() {
const batch = new Array(100);
for (let i = 0; i < 100; i++) {
for (let j = 0; j < 100; j++) {
batch[j] = fetch(url, {
// warmup the server with streaming requests, because is the most memory intensive
batch[j] = fetch(`${url.origin}/streaming`, {
method: "POST",
body: payload,
});
}
await Promise.all(batch);
}
// clean up memory before first test
await getMemoryUsage();
}

async function callBuffering() {
await fetch(`${url.origin}/buffering`, {
const result = await fetch(`${url.origin}/buffering`, {
method: "POST",
body: payload,
});
}).then(res => res.text());
expect(result).toBe("Ok");
}
async function callStreaming() {
const result = await fetch(`${url.origin}/streaming`, {
Expand Down Expand Up @@ -97,7 +101,6 @@ async function calculateMemoryLeak(fn: () => Promise<void>) {
}

// wait for the last memory usage to be stable
await Bun.sleep(100);
const end_memory = await getMemoryUsage();
if (end_memory > peak_memory) {
peak_memory = end_memory;
Expand All @@ -121,7 +124,6 @@ for (const test_info of [
testName,
async () => {
const report = await calculateMemoryLeak(fn);

// peak memory is too high
expect(report.peak_memory > report.start_memory * 2).toBe(false);
// acceptable memory leak
Expand Down

0 comments on commit fdbe9e2

Please sign in to comment.