test: inject platform to the serveCDP app

This commit is contained in:
Pierre Tachoire
2025-07-02 13:16:49 -07:00
parent 44a76e59f9
commit b78729f685
2 changed files with 6 additions and 11 deletions

View File

@@ -603,7 +603,7 @@ test "tests:beforeAll" {
log.opts.format = .logfmt;
test_wg.startMany(3);
_ = try Platform.init();
const platform = try Platform.init();
{
const address = try std.net.Address.parseIp("127.0.0.1", 9582);
@@ -619,7 +619,7 @@ test "tests:beforeAll" {
{
const address = try std.net.Address.parseIp("127.0.0.1", 9583);
const thread = try std.Thread.spawn(.{}, serveCDP, .{address});
const thread = try std.Thread.spawn(.{}, serveCDP, .{ address, &platform });
thread.detach();
}
@@ -801,11 +801,12 @@ fn serveHTTPS(address: std.net.Address) !void {
}
}
fn serveCDP(address: std.net.Address) !void {
fn serveCDP(address: std.net.Address, platform: *const Platform) !void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
var app = try App.init(gpa.allocator(), .{
.run_mode = .serve,
.tls_verify_host = false,
.platform = platform,
});
defer app.deinit();

View File

@@ -274,18 +274,12 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
}
pub fn pumpMessageLoop(self: *const Self) bool {
if (comptime builtin.is_test) {
if (self.platform == null) return false;
}
// assume it's not-null in non-test.
// assume it's not-null.
return self.platform.?.inner.pumpMessageLoop(self.isolate, false);
}
pub fn runIdleTasks(self: *const Self) void {
if (comptime builtin.is_test) {
if (self.platform == null) return;
}
// assume it's not-null in non-test.
// assume it's not-null.
return self.platform.?.inner.runIdleTasks(self.isolate, 1);
}