Skip to content

Lightpanda: the headless browser designed for AI and automation

chore: speed up unit tests on linux

Karl Seguin73de272755bd
diff --git a/src/TestHTTPServer.zig b/src/TestHTTPServer.zig
index 46649de33..574fb125a 100644
--- a/src/TestHTTPServer.zig
+++ b/src/TestHTTPServer.zig
@@ -19,6 +19,7 @@
const std = @import("std");
const lp = @import("lightpanda");
+const posix = std.posix;
const sys_net = @import("sys/net.zig");
const URL = @import("browser/URL.zig");
@@ -76,6 +77,10 @@ pub fn run(self: *TestHTTPServer, wg: *lp.WaitGroup) !void {
fn handleConnection(self: *TestHTTPServer, conn: std.Io.net.Stream) !void {
defer conn.close(lp.io);
+ if (@hasDecl(posix.TCP, "NODELAY")) {
+ posix.setsockopt(conn.socket.handle, posix.IPPROTO.TCP, posix.TCP.NODELAY, &std.mem.toBytes(@as(c_int, 1))) catch {};
+ }
+
var req_buf: [2048]u8 = undefined;
var conn_reader = conn.reader(lp.io, &req_buf);
var conn_writer = conn.writer(lp.io, &req_buf);
diff --git a/src/TestWSServer.zig b/src/TestWSServer.zig
index 971b3f8df..ed24c380a 100644
--- a/src/TestWSServer.zig
+++ b/src/TestWSServer.zig
@@ -87,6 +87,10 @@ fn runImpl(self: *TestWSServer, wg: *lp.WaitGroup) !void {
fn handleClient(client: posix.socket_t) void {
defer _ = std.c.close(client);
+ if (@hasDecl(posix.TCP, "NODELAY")) {
+ posix.setsockopt(client, posix.IPPROTO.TCP, posix.TCP.NODELAY, &std.mem.toBytes(@as(c_int, 1))) catch {};
+ }
+
var buf: [4096]u8 = undefined;
const n = posix.read(client, &buf) catch return;