diff --git a/test/js/bun/http/serve-http3.test.ts b/test/js/bun/http/serve-http3.test.ts index 9869238fc1f6..e5ee69ac9d62 100644 --- a/test/js/bun/http/serve-http3.test.ts +++ b/test/js/bun/http/serve-http3.test.ts @@ -1016,7 +1016,9 @@ describe("Bun.serve HTTP/3 lifecycle", () => { `; await withCustomServer(script, async (port, send, waitForStderr) => { expect(await fetchH3(port, "/").then(r => r.text())).toBe("ok"); - const inflight = fetchH3(port, "/stop", { + // The rejection can reach this thread before the STOPPED line does, so + // the handlers are on the promise before the wait. + const outcome = fetchH3(port, "/stop", { method: "POST", body: new ReadableStream({ start(c) { @@ -1024,10 +1026,11 @@ describe("Bun.serve HTTP/3 lifecycle", () => { c.close(); }, }), - }); + }) + .then(r => r.text()) + .catch(e => e.code); await waitForStderr(/STOPPED/); - const outcome = await inflight.then(r => r.text()).catch(e => e.code); - expect(outcome).toBe("HTTP3StreamReset"); + expect(await outcome).toBe("HTTP3StreamReset"); }); });