Skip to content

Commit

Permalink
http_auth test: http client code "fix"; also: 1 use 1 worker instead …
Browse files Browse the repository at this point in the history
…of 0 explicitly
  • Loading branch information
renerocksai committed Dec 30, 2023
1 parent 790ee37 commit 012452e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/bindataformpost/bindataformpost.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ pub fn main() !void {

zap.start(.{
.threads = 1,
.workers = 0,
.workers = 1,
});
}
2 changes: 1 addition & 1 deletion examples/cookies/cookies.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ pub fn main() !void {
defer thread.join();
zap.start(.{
.threads = 1,
.workers = 0,
.workers = 1,
});
}
2 changes: 1 addition & 1 deletion examples/http_params/http_params.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ pub fn main() !void {
defer thread.join();
zap.start(.{
.threads = 1,
.workers = 0,
.workers = 1,
});
}
2 changes: 1 addition & 1 deletion examples/sendfile/sendfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ pub fn main() !void {

zap.start(.{
.threads = 1,
.workers = 0,
.workers = 1,
});
}
34 changes: 21 additions & 13 deletions src/tests/test_auth.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_http_params.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test "http parameters" {
defer thread.join();
zap.start(.{
.threads = 1,
.workers = 0,
.workers = 1,
});

defer {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_sendfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test "send file" {
defer thread.join();
zap.start(.{
.threads = 1,
.workers = 0,
.workers = 1,
});

if (read_len) |rl| {
Expand Down

0 comments on commit 012452e

Please sign in to comment.