Skip to content

Commit

Permalink
promise should be alive
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed May 16, 2024
1 parent cacc4ac commit 99552fb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/js/web/fetch/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1991,3 +1991,32 @@ describe("fetch Response life cycle", () => {
serverProcess.kill();
}
});
it("should allow to get promise result after response is GC'd", async () => {
const server = Bun.serve({
async fetch(request: Request) {
return new Response(
new ReadableStream({
async pull(controller) {
await Bun.sleep(100);
controller.enqueue(new TextEncoder().encode("Hello, World!"));
await Bun.sleep(100);
controller.close();
},
}),
{ status: 200 },
);
},
});
async function fetchResponse() {
const response = await fetch(`${server.url.origin}/non-empty`);
return response.text();
}
try {
const response_promise = fetchResponse();
Bun.gc(true);
expect(await response_promise).toBe("Hello, World!");
} finally {
server.stop(true);
}
});
});

0 comments on commit 99552fb

Please sign in to comment.