Something went wrong. Try again.
xburner is an experimental HTTP and gRPC load generator written in Zig.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071const std = @import("std");
const config = @import("../config.zig");const http_executor = @import("../protocol/http_executor.zig");const runner_log = @import("log.zig");const template = @import("../template.zig");
const http = std.http;
const TlsContext = http_executor.TlsContext;
pub fn runSetupPhase( allocator: std.mem.Allocator, client: *http.Client, store: *template.VarStore, tls_context: *TlsContext, scenario: *const config.ScenarioConfig, logger: *runner_log.Logger,) !void { const default_timeout_ms = durationToTimeoutMs(scenario.execution.setup_timeout); for (scenario.setup.requests) |request| { var execution = http_executor.executeRequest( allocator, client, store, tls_context, null, scenario.scenario.target, request.method, request.path, request.headers, request.body, null, 0, if (request.timeout_ms != 0) request.timeout_ms else default_timeout_ms, 0, request.capture_body_max_bytes, ) catch |err| { const error_message = try http_executor.describeRequestError(allocator, err, &scenario.http); defer allocator.free(error_message); try logger.logf(.err, .{ .component = "runner", .source = .host, .event = "setup_request_failed", }, "setup request `{s}` failed: {s}", .{ request.name, error_message }); return error.SetupFailed; }; defer execution.deinit(allocator);
if (!execution.success) { try logger.logf(.err, .{ .component = "runner", .source = .host, .event = "setup_request_failed", }, "setup request `{s}` failed with status {d}", .{ request.name, execution.status_code }); return error.SetupFailed; }
if (request.store_body_as) |store_key| { const body = execution.captured_body orelse ""; try store.set(store_key, body); } }}
fn durationToTimeoutMs(duration: config.Duration) u32 { if (duration.nanos == 0) return 0; const millis = @divTrunc(duration.nanos, std.time.ns_per_ms); return @intCast(@min(millis, std.math.maxInt(u32)));}