From 0bfd8235f74e42f4b2d5e4687c4650dfe3b268d0 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Mon, 17 Apr 2023 04:01:43 +0200 Subject: [PATCH] test auth: wait for response to be sent before stopping zap --- src/http_client_testrunner.zig | 18 ++++++++++-------- src/test_auth.zig | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/http_client_testrunner.zig b/src/http_client_testrunner.zig index b2790d3..6d3b2a1 100644 --- a/src/http_client_testrunner.zig +++ b/src/http_client_testrunner.zig @@ -1,5 +1,7 @@ const std = @import("std"); +const seconds_between_steps: usize = 3; + pub fn main() !void { const a = std.heap.page_allocator; @@ -12,7 +14,7 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - std.time.sleep(3 * std.time.ns_per_s); + std.time.sleep(seconds_between_steps * std.time.ns_per_s); p = std.ChildProcess.init(&.{ "./zig-out/bin/http_client", @@ -22,7 +24,7 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - std.time.sleep(3 * std.time.ns_per_s); + std.time.sleep(seconds_between_steps * std.time.ns_per_s); // Bearer Multi p = std.ChildProcess.init(&.{ @@ -33,7 +35,7 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - std.time.sleep(3 * std.time.ns_per_s); + std.time.sleep(seconds_between_steps * std.time.ns_per_s); p = std.ChildProcess.init(&.{ "./zig-out/bin/http_client", @@ -43,7 +45,7 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - std.time.sleep(3 * std.time.ns_per_s); + std.time.sleep(seconds_between_steps * std.time.ns_per_s); // Basic p = std.ChildProcess.init(&.{ @@ -54,7 +56,7 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - std.time.sleep(3 * std.time.ns_per_s); + std.time.sleep(seconds_between_steps * std.time.ns_per_s); p = std.ChildProcess.init(&.{ "./zig-out/bin/http_client", @@ -64,7 +66,7 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - std.time.sleep(3 * std.time.ns_per_s); + std.time.sleep(seconds_between_steps * std.time.ns_per_s); p = std.ChildProcess.init(&.{ "./zig-out/bin/http_client", @@ -74,7 +76,7 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - std.time.sleep(3 * std.time.ns_per_s); + std.time.sleep(seconds_between_steps * std.time.ns_per_s); p = std.ChildProcess.init(&.{ "./zig-out/bin/http_client", @@ -84,5 +86,5 @@ pub fn main() !void { }, a); _ = try p.spawnAndWait(); - // std.time.sleep(3 * std.time.ns_per_s); + // std.time.sleep(seconds_between_steps * std.time.ns_per_s); } diff --git a/src/test_auth.zig b/src/test_auth.zig index 6c2091b..485acb2 100644 --- a/src/test_auth.zig +++ b/src/test_auth.zig @@ -108,6 +108,7 @@ fn endpoint_http_get(e: *Endpoints.SimpleEndpoint, r: zap.SimpleRequest) void { _ = e; r.sendBody(HTTP_RESPONSE) catch return; received_response = HTTP_RESPONSE; + std.time.sleep(1 * std.time.ns_per_s); zap.fio_stop(); } @@ -117,6 +118,7 @@ fn endpoint_http_unauthorized(e: *Endpoints.SimpleEndpoint, r: zap.SimpleRequest r.sendBody("UNAUTHORIZED ACCESS") catch return; std.debug.print("\nunauthorized\n", .{}); received_response = "UNAUTHORIZED"; + std.time.sleep(1 * std.time.ns_per_s); zap.fio_stop(); }