mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 06:23:45 +00:00
Cleanup threads manager
This commit is contained in:
@@ -450,7 +450,9 @@ const TestHTTPServer = @import("TestHTTPServer.zig");
|
||||
|
||||
const Server = @import("Server.zig");
|
||||
var test_cdp_server: ?Server = null;
|
||||
var test_cdp_server_thread: ?std.Thread = null;
|
||||
var test_http_server: ?TestHTTPServer = null;
|
||||
var test_http_server_thread: ?std.Thread = null;
|
||||
|
||||
const test_config = Config{
|
||||
.mode = .{ .serve = .{
|
||||
@@ -480,16 +482,10 @@ test "tests:beforeAll" {
|
||||
var wg: std.Thread.WaitGroup = .{};
|
||||
wg.startMany(2);
|
||||
|
||||
{
|
||||
const thread = try std.Thread.spawn(.{}, serveCDP, .{&wg});
|
||||
thread.detach();
|
||||
}
|
||||
test_cdp_server_thread = try std.Thread.spawn(.{}, serveCDP, .{&wg});
|
||||
|
||||
test_http_server = TestHTTPServer.init(testHTTPHandler);
|
||||
{
|
||||
const thread = try std.Thread.spawn(.{}, TestHTTPServer.run, .{ &test_http_server.?, &wg });
|
||||
thread.detach();
|
||||
}
|
||||
test_http_server_thread = try std.Thread.spawn(.{}, TestHTTPServer.run, .{ &test_http_server.?, &wg });
|
||||
|
||||
// need to wait for the servers to be listening, else tests will fail because
|
||||
// they aren't able to connect.
|
||||
@@ -497,9 +493,21 @@ test "tests:beforeAll" {
|
||||
}
|
||||
|
||||
test "tests:afterAll" {
|
||||
if (test_cdp_server) |*server| {
|
||||
server.stop();
|
||||
}
|
||||
if (test_cdp_server_thread) |thread| {
|
||||
thread.join();
|
||||
}
|
||||
if (test_cdp_server) |*server| {
|
||||
server.deinit();
|
||||
}
|
||||
if (test_http_server) |*server| {
|
||||
server.stop();
|
||||
}
|
||||
if (test_http_server_thread) |thread| {
|
||||
thread.join();
|
||||
}
|
||||
if (test_http_server) |*server| {
|
||||
server.deinit();
|
||||
}
|
||||
@@ -515,9 +523,6 @@ fn serveCDP(wg: *std.Thread.WaitGroup) !void {
|
||||
const address = try std.net.Address.parseIp("127.0.0.1", 9583);
|
||||
const test_allocator = @import("root").tracking_allocator;
|
||||
test_cdp_server = try Server.init(test_allocator, test_app, address);
|
||||
|
||||
var server = try Server.init(test_allocator, test_app, address);
|
||||
defer server.deinit();
|
||||
wg.finish();
|
||||
|
||||
test_cdp_server.?.run(address, 5) catch |err| {
|
||||
|
||||
Reference in New Issue
Block a user