Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions test/js/bun/http/serve-reused-response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { bunEnv, bunExe } from "harness";
// A fetch handler that returns a Response whose body has already been used
// (most often the same Response object returned for every request) must invoke
// the error handler instead of silently sending a 200 with an empty body.
describe("returning a Response with an already-used body", () => {
// Every case spins up its own port-0 server and shares no state, so the whole
// block runs concurrently to keep wall time bounded by the single subprocess spawn.
describe.concurrent("returning a Response with an already-used body", () => {
const alreadyUsedError = {
code: "ERR_BODY_ALREADY_USED",
name: "TypeError",
Expand Down Expand Up @@ -102,6 +104,7 @@ describe("returning a Response with an already-used body", () => {

it("a Response reused through a static route keeps working", async () => {
// Static routes snapshot the body at registration, so reuse is allowed there.
const error = jest.fn();
await using server = serve({
port: 0,
routes: {
Expand All @@ -110,13 +113,15 @@ describe("returning a Response with an already-used body", () => {
fetch() {
return new Response("fallback");
},
error,
});

for (let i = 0; i < 3; i++) {
const response = await fetch(new URL("/static", server.url));
expect(await response.text()).toBe("static-body");
expect(response.status).toBe(200);
}
expect(error).not.toHaveBeenCalled();
});

it("without an error handler, logs the error and responds with 500", async () => {
Expand All @@ -138,7 +143,13 @@ describe("returning a Response with an already-used body", () => {
console.log(second.status, JSON.stringify(await second.text()));
server.stop(true);`,
],
env: bunEnv,
env: {
...bunEnv,
// On the ASAN CI lane bunEnv forwards detect_leaks=1 via process.env,
// turning this behavior probe into a ~24s leak scan at exit. Disable leak
// detection for the subprocess; the outer test process still runs under LSan.
ASAN_OPTIONS: [bunEnv.ASAN_OPTIONS, "detect_leaks=0"].filter(Boolean).join(":"),
},
stdout: "pipe",
stderr: "pipe",
});
Expand Down
Loading