Skip to content

Commit 2b3d893

Browse files
committed
Fix fetch-preconnect test failure
1 parent 0511fbf commit 2b3d893

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/http/HTTPContext.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ pub fn NewHTTPContext(comptime ssl: bool) type {
412412

413413
if (strings.eqlLong(socket.hostname_buf[0..socket.hostname_len], hostname, true)) {
414414
const http_socket = socket.http_socket;
415-
assert(context().pending_sockets.put(socket));
416415

417416
if (http_socket.isClosed()) {
418417
markSocketAsDead(http_socket);
@@ -424,6 +423,7 @@ pub fn NewHTTPContext(comptime ssl: bool) type {
424423
continue;
425424
}
426425

426+
assert(context().pending_sockets.put(socket));
427427
log("+ Keep-Alive reuse {s}:{d}", .{ hostname, port });
428428
return http_socket;
429429
}

test/js/web/fetch/fetch-preconnect.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { describe, expect, it } from "bun:test";
22
import "harness";
3-
import { isWindows } from "harness";
3+
import { bunEnv, bunExe, isWindows } from "harness";
44

55
// TODO: on Windows, these tests fail.
66
// This feature is mostly meant for serverless JS environments, so we can no-op it on Windows.
7-
describe.todoIf(isWindows)("fetch.preconnect", () => {
7+
describe.concurrent.todoIf(isWindows)("fetch.preconnect", () => {
88
it("fetch.preconnect works", async () => {
9-
const { promise, resolve } = Promise.withResolvers();
9+
const { promise, resolve } = Promise.withResolvers<Bun.Socket>();
1010
using listener = Bun.listen({
1111
port: 0,
1212
hostname: "localhost",
@@ -29,12 +29,12 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
2929
expect(response.status).toBe(200);
3030
});
3131

32-
describe("doesn't break the request when", () => {
32+
describe.concurrent("doesn't break the request when", () => {
3333
for (let endOrTerminate of ["end", "terminate", "shutdown"]) {
3434
describe(endOrTerminate, () => {
3535
for (let at of ["before", "middle", "after"]) {
3636
it(at, async () => {
37-
let { promise, resolve } = Promise.withResolvers();
37+
let { promise, resolve } = Promise.withResolvers<Bun.Socket>();
3838
using listener = Bun.listen({
3939
port: 0,
4040
hostname: "localhost",
@@ -48,7 +48,7 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
4848
});
4949
fetch.preconnect(`http://localhost:${listener.port}`);
5050
let socket = await promise;
51-
({ promise, resolve } = Promise.withResolvers());
51+
({ promise, resolve } = Promise.withResolvers<Bun.Socket>());
5252
if (at === "before") {
5353
await Bun.sleep(16);
5454
socket[endOrTerminate]();
@@ -86,7 +86,7 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
8686
});
8787

8888
it("--fetch-preconnect works", async () => {
89-
const { promise, resolve } = Promise.withResolvers();
89+
const { promise, resolve } = Promise.withResolvers<void>();
9090
using listener = Bun.listen({
9191
port: 0,
9292
hostname: "localhost",
@@ -102,7 +102,13 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
102102
});
103103

104104
// Do --fetch-preconnect, but don't actually send a request.
105-
expect([`--fetch-preconnect=http://localhost:${listener.port}`, "--eval", "Bun.sleep(64)"]).toRun();
105+
await using proc = Bun.spawn({
106+
cmd: [bunExe(), `--fetch-preconnect=http://localhost:${listener.port}`, "--eval", "Bun.sleep(64)"],
107+
stdio: ["inherit", "inherit", "inherit"],
108+
env: bunEnv,
109+
});
110+
111+
expect(await proc.exited).toBe(0);
106112

107113
await promise;
108114
});

0 commit comments

Comments
 (0)