@@ -109,13 +109,9 @@ fn run(alloc: Allocator) !void {
109109 log .opts .filter_scopes = lfs ;
110110 }
111111
112- const platform = try Platform .init ();
113- defer platform .deinit ();
114-
115112 // _app is global to handle graceful shutdown.
116113 _app = try App .init (alloc , .{
117114 .run_mode = args .mode ,
118- .platform = & platform ,
119115 .http_proxy = args .httpProxy (),
120116 .proxy_bearer_token = args .proxyBearerToken (),
121117 .tls_verify_host = args .tlsVerifyHost (),
@@ -124,6 +120,7 @@ fn run(alloc: Allocator) !void {
124120 .http_max_host_open = args .httpMaxHostOpen (),
125121 .http_max_concurrent = args .httpMaxConcurrent (),
126122 });
123+
127124 const app = _app .? ;
128125 defer app .deinit ();
129126 app .telemetry .record (.{ .run = {} });
@@ -715,48 +712,46 @@ fn parseCommonArg(
715712 return false ;
716713}
717714
715+ const testing = @import ("testing.zig" );
718716test {
719717 std .testing .refAllDecls (@This ());
720718}
721719
722- var test_wg : std.Thread.WaitGroup = .{};
723720test "tests:beforeAll" {
724- try parser .init ();
725721 log .opts .level = .err ;
726722 log .opts .format = .logfmt ;
727723
728- test_wg .startMany (2 );
729- const platform = try Platform .init ();
724+ try testing .setup ();
725+
726+ var wg : std.Thread.WaitGroup = .{};
727+ wg .startMany (2 );
730728
731729 {
732- const address = try std .net .Address .parseIp ("127.0.0.1" , 9582 );
733- const thread = try std .Thread .spawn (.{}, serveHTTP , .{address });
730+ const thread = try std .Thread .spawn (.{}, serveHTTP , .{& wg });
734731 thread .detach ();
735732 }
736733
737734 {
738- const address = try std .net .Address .parseIp ("127.0.0.1" , 9583 );
739- const thread = try std .Thread .spawn (.{}, serveCDP , .{ address , & platform });
735+ const thread = try std .Thread .spawn (.{}, serveCDP , .{& wg });
740736 thread .detach ();
741737 }
742738
743739 // need to wait for the servers to be listening, else tests will fail because
744740 // they aren't able to connect.
745- test_wg .wait ();
741+ wg .wait ();
746742}
747743
748744test "tests:afterAll" {
749- parser . deinit ();
745+ testing . shutdown ();
750746}
751747
752- fn serveHTTP (address : std.net.Address ) ! void {
753- var arena = std .heap .ArenaAllocator .init (std .testing .allocator );
754- defer arena .deinit ();
748+ fn serveHTTP (wg : * std.Thread.WaitGroup ) ! void {
749+ const address = try std .net .Address .parseIp ("127.0.0.1" , 9582 );
755750
756751 var listener = try address .listen (.{ .reuse_address = true });
757752 defer listener .deinit ();
758753
759- test_wg .finish ();
754+ wg .finish ();
760755
761756 var read_buffer : [1024 ]u8 = undefined ;
762757 while (true ) {
@@ -799,19 +794,12 @@ fn serveHTTP(address: std.net.Address) !void {
799794 }
800795}
801796
802- fn serveCDP (address : std.net.Address , platform : * const Platform ) ! void {
803- var gpa : std .heap .GeneralPurposeAllocator (.{}) = .init ;
804- var app = try App .init (gpa .allocator (), .{
805- .run_mode = .serve ,
806- .tls_verify_host = false ,
807- .platform = platform ,
808- .http_max_concurrent = 2 ,
809- });
810- defer app .deinit ();
797+ fn serveCDP (wg : * std.Thread.WaitGroup ) ! void {
798+ const address = try std .net .Address .parseIp ("127.0.0.1" , 9583 );
811799
812- test_wg .finish ();
813- var server = try Server .init (app , address );
800+ var server = try Server .init (testing .test_app , address );
814801 defer server .deinit ();
802+ wg .finish ();
815803 server .run (address , 5 ) catch | err | {
816804 std .debug .print ("CDP server error: {}" , .{err });
817805 return err ;
0 commit comments