aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar cirospaciari <ciro.spaciari@gmail.com> 2023-09-29 22:15:31 -0300
committerGravatar cirospaciari <ciro.spaciari@gmail.com> 2023-09-29 22:15:31 -0300
commit1ba11c0de39d4cd8e176f7bf9cd4780190b8a186 (patch)
tree1112379ec069d24cf956f87b84225d851b7ea77a
parent1ca8d0fb535cc39f15a9c5d71b109dc26645accd (diff)
downloadbun-1ba11c0de39d4cd8e176f7bf9cd4780190b8a186.tar.gz
bun-1ba11c0de39d4cd8e176f7bf9cd4780190b8a186.tar.zst
bun-1ba11c0de39d4cd8e176f7bf9cd4780190b8a186.zip
1 more lock testciro/fetch-fix-with-lock
-rw-r--r--test/js/web/fetch/fetch.stream.test.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/js/web/fetch/fetch.stream.test.ts b/test/js/web/fetch/fetch.stream.test.ts
index 5473358d4..fb2bb2699 100644
--- a/test/js/web/fetch/fetch.stream.test.ts
+++ b/test/js/web/fetch/fetch.stream.test.ts
@@ -122,6 +122,53 @@ describe("fetch() with streaming", () => {
}
});
+ it(`should be locked after start buffering when calling getReader`, async () => {
+ let server: Server | null = null;
+ try {
+ server = Bun.serve({
+ port: 0,
+ fetch(req) {
+ return new Response(
+ new ReadableStream({
+ async start(controller) {
+ controller.enqueue("Hello, World!");
+ await Bun.sleep(10);
+ controller.enqueue("Hello, World!");
+ await Bun.sleep(10);
+ controller.enqueue("Hello, World!");
+ await Bun.sleep(10);
+ controller.enqueue("Hello, World!");
+ await Bun.sleep(10);
+ controller.close();
+ },
+ }),
+ {
+ status: 200,
+ headers: {
+ "Content-Type": "text/plain",
+ },
+ },
+ );
+ },
+ });
+
+ const server_url = `http://${server.hostname}:${server.port}`;
+ const res = await fetch(server_url);
+ try {
+ const body = res.body as ReadableStream<Uint8Array>;
+ const promise = res.text(); // start buffering
+ body.getReader(); // get a reader
+ const result = await promise; // should throw the right error
+ expect(result).toBe("unreachable");
+ } catch (err: any) {
+ if (err.name !== "TypeError") throw err;
+ expect(err.message).toBe("ReadableStream is locked");
+ }
+ } finally {
+ server?.stop();
+ }
+ });
+
it("can deflate with and without headers #4478", async () => {
let server: Server | null = null;
try {