Skip to content

Commit 37d6401

Browse files
committed
Fix browser fallback test
1 parent a8c749c commit 37d6401

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

src/root/tests.zig

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,16 @@ test "websocket upgrade survives repeated connect-disconnect churn" {
265265
test "mixed concurrent http routes remain stable under socket churn" {
266266
const Shared = struct { failed: std.atomic.Value(bool) = std.atomic.Value(bool).init(false) };
267267
const Ctx = struct {
268-
allocator: std.mem.Allocator,
269268
port: u16,
270269
start: usize,
271270
shared: *Shared,
272271
};
273272
const Worker = struct {
274273
fn run(ctx: *Ctx) void {
274+
var gpa_thread = std.heap.GeneralPurposeAllocator(.{}){};
275+
defer _ = gpa_thread.deinit();
276+
const allocator = gpa_thread.allocator();
277+
275278
var i: usize = 0;
276279
while (i < 40) : (i += 1) {
277280
const route_idx = (ctx.start + i) % 3;
@@ -280,11 +283,11 @@ test "mixed concurrent http routes remain stable under socket churn" {
280283
1 => "/webui/window/control",
281284
else => "/webui/window/style",
282285
};
283-
const response = httpRoundTrip(ctx.allocator, ctx.port, "GET", path, null) catch {
286+
const response = httpRoundTrip(allocator, ctx.port, "GET", path, null) catch {
284287
ctx.shared.failed.store(true, .release);
285288
return;
286289
};
287-
defer ctx.allocator.free(response);
290+
defer allocator.free(response);
288291

289292
if (std.mem.indexOf(u8, response, "HTTP/1.1 200 OK") == null) {
290293
ctx.shared.failed.store(true, .release);
@@ -311,7 +314,6 @@ test "mixed concurrent http routes remain stable under socket churn" {
311314
var threads: [8]std.Thread = undefined;
312315
for (&contexts, 0..) |*ctx, idx| {
313316
ctx.* = .{
314-
.allocator = gpa.allocator(),
315317
.port = win.state().server_port,
316318
.start = idx * 7,
317319
.shared = &shared,
@@ -364,9 +366,19 @@ test "window control route stays responsive during long running rpc" {
364366
err: ?anyerror = null,
365367

366368
fn run(ctx: *@This()) void {
367-
const result = httpRoundTrip(ctx.allocator, ctx.port, "POST", "/webui/rpc", "{\"name\":\"slow\",\"args\":[]}");
369+
var gpa_thread = std.heap.GeneralPurposeAllocator(.{}){};
370+
defer _ = gpa_thread.deinit();
371+
const allocator = gpa_thread.allocator();
372+
373+
const result = httpRoundTrip(allocator, ctx.port, "POST", "/webui/rpc", "{\"name\":\"slow\",\"args\":[]}");
368374
if (result) |response| {
369-
ctx.response = response;
375+
const copied = ctx.allocator.dupe(u8, response) catch {
376+
allocator.free(response);
377+
ctx.err = error.OutOfMemory;
378+
return;
379+
};
380+
allocator.free(response);
381+
ctx.response = copied;
370382
} else |err| {
371383
ctx.err = err;
372384
}
@@ -389,7 +401,7 @@ test "window control route stays responsive during long running rpc" {
389401
try app.run();
390402

391403
var rpc_call_ctx = RpcCallCtx{
392-
.allocator = gpa.allocator(),
404+
.allocator = std.heap.page_allocator,
393405
.port = win.state().server_port,
394406
};
395407
const rpc_thread = try std.Thread.spawn(.{}, RpcCallCtx.run, .{&rpc_call_ctx});
@@ -415,7 +427,7 @@ test "window control route stays responsive during long running rpc" {
415427

416428
if (rpc_call_ctx.err) |err| return err;
417429
const rpc_response = rpc_call_ctx.response orelse return error.InvalidRpcResult;
418-
defer gpa.allocator().free(rpc_response);
430+
defer rpc_call_ctx.allocator.free(rpc_response);
419431
try std.testing.expectEqualStrings("\"done\"", httpResponseBody(rpc_response));
420432
}
421433

0 commit comments

Comments
 (0)