Skip to content

Lightpanda: the headless browser designed for AI and automation

improve macos test stability

Karl Seguinfaad8859139d
diff --git a/src/server/Link.zig b/src/server/Link.zig
index f37a78950..e27651a01 100644
--- a/src/server/Link.zig
+++ b/src/server/Link.zig
@@ -330,8 +330,11 @@ test "link: send gives up when the peer stops reading" {
// only half-closes the read side, hangs the whole process on SIGINT.
try testing.expectError(error.Timeout, link.send(payload));
- // and the run loop's reads share the fd: it must still be non-blocking
- try testing.expectEqual(flags | nonblocking, try sys_net.fcntl(pair[1], posix.F.GETFL, 0));
+ // and the run loop's reads share the fd: it must still be non-blocking.
+ // Only the bit, not the whole word: macOS leaks FWASWRITTEN (0x10000)
+ // into F_GETFL once the fd has been written to.
+ const after = try sys_net.fcntl(pair[1], posix.F.GETFL, 0);
+ try testing.expectEqual(nonblocking, after & nonblocking);
}
test "link: stops reading once the worker's inbox backs up" {
diff --git a/src/server/Server.zig b/src/server/Server.zig
index efc9346e4..6b0a7b967 100644
--- a/src/server/Server.zig
+++ b/src/server/Server.zig
@@ -2134,7 +2134,7 @@ const LoopTest = struct {
try posix.setsockopt(client, posix.SOL.SOCKET, posix.SO.RCVTIMEO, &timeout);
const before = self.server.http_connections.last;
- try waitReadable(self.server.listener);
+ try pollReadable(self.server.listener);
try self.server.accept(lp.datetime.milliTimestamp(.boot));
const node = self.server.http_connections.last orelse return error.NotAccepted;
@@ -2147,7 +2147,7 @@ const LoopTest = struct {
// macOS delivers loopback traffic asynchronously: right after connect()
// or write() returns, the peer's accept queue or read buffer can still be
// empty. Linux processes it inline, so these tests never waited there.
- fn waitReadable(fd: posix.socket_t) !void {
+ fn pollReadable(fd: posix.socket_t) !void {
var pfd = [_]posix.pollfd{.{ .fd = fd, .events = posix.POLL.IN, .revents = 0 }};
if (try posix.poll(&pfd, 1000) == 0) {
return error.Timeout;
@@ -2169,7 +2169,7 @@ test "server: a shutdown in the same batch as a readable connection" {
lt.server.shutdown();
// ...then the request, so it lands behind it in the batch
try sys_net.writeAll(client, "GET /json/version HTTP/1.1\r\n\r\n");
- try LoopTest.waitReadable(conn.socket);
+ try LoopTest.pollReadable(conn.socket);
// beginShutdown drops every http connection, so running it where it
// arrived left the rest of the batch pointing at a recycled (or freed)
@@ -2194,9 +2194,12 @@ test "server: an accept at the connection limit in the same batch as a readable
// the accept first...
const second = try sys_net.connect(&lt.address);
defer sys_net.close(second);
+ // the listener has to be in the batch too, or runOnce() sees the request
+ // alone and saturated() -- the thing under test -- never runs
+ try LoopTest.pollReadable(lt.server.listener);
// ...then the request, so it lands behind it in the batch
try sys_net.writeAll(client, "GET /json/version HTTP/1.1\r\n\r\n");
- try LoopTest.waitReadable(conn.socket);
+ try LoopTest.pollReadable(conn.socket);
// saturated() picks the idle connection to drop, which is the one the
// batch is still holding a pointer to. Its request comes first.
@@ -2301,7 +2304,7 @@ test "server: http connections stay ordered by deadline" {
const client_a, const conn_a = try lt.accept();
defer sys_net.close(client_a);
try sys_net.writeAll(client_a, "GET /json/version HTTP/1.1\r\n\r\n");
- try LoopTest.waitReadable(conn_a.socket);
+ try LoopTest.pollReadable(conn_a.socket);
const readable: IOEvent.ReadWrite = .{ .target = .{ .http = conn_a }, .readable = true, .writable = false, .hangup = false };
http.processEvent(lt.server, conn_a, readable, lp.datetime.milliTimestamp(.boot));