From 012452e1e1a5f5f79442578ac91e405bfb9f8d25 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Sun, 31 Dec 2023 00:16:36 +0100 Subject: [PATCH] http_auth test: http client code "fix"; also: 1 use 1 worker instead of 0 explicitly --- examples/bindataformpost/bindataformpost.zig | 2 +- examples/cookies/cookies.zig | 2 +- examples/http_params/http_params.zig | 2 +- examples/sendfile/sendfile.zig | 2 +- src/tests/test_auth.zig | 34 ++++++++++++-------- src/tests/test_http_params.zig | 2 +- src/tests/test_sendfile.zig | 2 +- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/examples/bindataformpost/bindataformpost.zig b/examples/bindataformpost/bindataformpost.zig index 1a60849..44f6a8e 100644 --- a/examples/bindataformpost/bindataformpost.zig +++ b/examples/bindataformpost/bindataformpost.zig @@ -110,6 +110,6 @@ pub fn main() !void { zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); } diff --git a/examples/cookies/cookies.zig b/examples/cookies/cookies.zig index 67ab034..9fba109 100644 --- a/examples/cookies/cookies.zig +++ b/examples/cookies/cookies.zig @@ -115,6 +115,6 @@ pub fn main() !void { defer thread.join(); zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); } diff --git a/examples/http_params/http_params.zig b/examples/http_params/http_params.zig index 1bb739d..48d0f12 100644 --- a/examples/http_params/http_params.zig +++ b/examples/http_params/http_params.zig @@ -115,6 +115,6 @@ pub fn main() !void { defer thread.join(); zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); } diff --git a/examples/sendfile/sendfile.zig b/examples/sendfile/sendfile.zig index daf16dd..b7099e7 100644 --- a/examples/sendfile/sendfile.zig +++ b/examples/sendfile/sendfile.zig @@ -44,6 +44,6 @@ pub fn main() !void { zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); } diff --git a/src/tests/test_auth.zig b/src/tests/test_auth.zig index 2b5e246..4055695 100644 --- a/src/tests/test_auth.zig +++ b/src/tests/test_auth.zig @@ -152,11 +152,19 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8, auth: ?ClientAuthReqHeader try req.start(); try req.wait(); - // var br = std.io.bufferedReaderSize(std.crypto.tls.max_ciphertext_record_len, req.reader()); - // var buffer: [1024]u8 = undefined; - // we know we won't receive a lot - // const len = try br.reader().readAll(&buffer); - // std.debug.print("RESPONSE:\n{s}\n", .{buffer[0..len]}); + // req.deinit() panics! + // defer req.deinit(); + + // without this block, the tests sometimes get stuck which + // might have to do with connection pooling and connections being in + // a different state when all data has been read?!? + { + var buffer: [1024]u8 = undefined; + // we know we won't receive a lot + const len = try req.reader().readAll(&buffer); + std.debug.print("RESPONSE:\n{s}\n", .{buffer[0..len]}); + } + zap.fio_stop(); } @@ -215,7 +223,7 @@ test "BearerAuthSingle authenticateRequest OK" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings(HTTP_RESPONSE, received_response); @@ -272,7 +280,7 @@ test "BearerAuthSingle authenticateRequest test-unauthorized" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings("UNAUTHORIZED", received_response); @@ -323,7 +331,7 @@ test "BearerAuthMulti authenticateRequest OK" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings(HTTP_RESPONSE, received_response); @@ -374,7 +382,7 @@ test "BearerAuthMulti authenticateRequest test-unauthorized" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings(HTTP_RESPONSE, received_response); @@ -430,7 +438,7 @@ test "BasicAuth Token68 authenticateRequest" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings(HTTP_RESPONSE, received_response); @@ -486,7 +494,7 @@ test "BasicAuth Token68 authenticateRequest test-unauthorized" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings("UNAUTHORIZED", received_response); @@ -552,7 +560,7 @@ test "BasicAuth UserPass authenticateRequest" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings(HTTP_RESPONSE, received_response); @@ -619,7 +627,7 @@ test "BasicAuth UserPass authenticateRequest test-unauthorized" { // start worker threads zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); try std.testing.expectEqualStrings("UNAUTHORIZED", received_response); diff --git a/src/tests/test_http_params.zig b/src/tests/test_http_params.zig index 14f8fdc..00b23bc 100644 --- a/src/tests/test_http_params.zig +++ b/src/tests/test_http_params.zig @@ -71,7 +71,7 @@ test "http parameters" { defer thread.join(); zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); defer { diff --git a/src/tests/test_sendfile.zig b/src/tests/test_sendfile.zig index 31af22c..5b0f5c4 100644 --- a/src/tests/test_sendfile.zig +++ b/src/tests/test_sendfile.zig @@ -52,7 +52,7 @@ test "send file" { defer thread.join(); zap.start(.{ .threads = 1, - .workers = 0, + .workers = 1, }); if (read_len) |rl| {