Something went wrong. Try again.
xburner is an experimental HTTP and gRPC load generator written in Zig.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425const std = @import("std");
const config = @import("../config.zig");const literals = @import("literals.zig");
const ByteSize = config.ByteSize;const CookieJarScope = config.CookieJarScope;const Duration = config.Duration;const Execution = config.Execution;const HttpMethod = config.HttpMethod;const ScenarioConfig = config.ScenarioConfig;const ScenarioMode = config.ScenarioMode;const ThresholdMetric = config.ThresholdMetric;const ThresholdOperator = config.ThresholdOperator;const ThresholdValue = config.ThresholdValue;const WasmBackend = config.WasmBackend;
test "parse workflow config with setup requests and thresholds" { const source = \\[scenario] \\name = "http-login-flow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-arrival-rate" \\rate = 200 \\duration = "60s" \\warmup = "5s" \\pre_allocated_vus = 64 \\max_vus = 128 \\ \\[[setup.requests]] \\name = "bootstrap-auth" \\method = "POST" \\path = "/v1/bootstrap-login" \\headers = { content-type = "application/json" } \\body = "{\"username\":\"seed-user\",\"password\":\"seed-pass\"}" \\store_body_as = "setup.BOOTSTRAP_LOGIN_BODY" \\capture_body_max_bytes = 4096 \\ \\[http.defaults] \\use_tls = true \\cookie_jar = true \\cookie_jar_scope = "vu" \\max_steps_per_iteration = 16 \\ \\[http.defaults.tls] \\ca_file = "./certs/ca.pem" \\insecure_skip_verify = false \\server_name = "example.internal" \\ \\[[http.requests]] \\id = 1 \\name = "login" \\method = "POST" \\path = "/v1/login" \\headers = { content-type = "application/json" } \\timeout_ms = 1000 \\pass_response_body = true \\capture_body_max_bytes = 2048 \\ \\[[http.requests]] \\id = 2 \\name = "get-me" \\method = "GET" \\path = "/v1/me" \\headers = { authorization = "Bearer ${iter.TOKEN}" } \\timeout_ms = 1000 \\pass_response_body = true \\capture_body_max_bytes = 4096 \\ \\[[http.requests]] \\id = 3 \\name = "get-orders" \\method = "GET" \\path = "/v1/orders/${iter.USER_ID}" \\headers = { authorization = "Bearer ${iter.TOKEN}" } \\timeout_ms = 1000 \\delay_before_ms = 250 \\pass_response_body = false \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\scope = { request = "login" } \\op = "<=" \\value = "500ms" \\ \\[[thresholds]] \\metric = "http.error_rate" \\op = "<=" \\value = "0.01" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(ScenarioMode.workflow, parsed.scenario.mode()); try std.testing.expectEqual(Execution.Mode.constant_arrival_rate, parsed.execution.mode); try std.testing.expectEqual(Duration.fromSeconds(60).nanos, parsed.execution.duration.nanos); try std.testing.expectEqual(Duration.fromSeconds(5).nanos, parsed.execution.warmup.nanos); try std.testing.expectEqual(true, parsed.http.defaults.use_tls); try std.testing.expectEqual(CookieJarScope.vu, parsed.http.defaults.cookie_jar_scope); try std.testing.expectEqualStrings("./certs/ca.pem", parsed.http.defaults.tls.ca_file.?); try std.testing.expectEqual(@as(usize, 1), parsed.setup.requests.len); try std.testing.expectEqualStrings("setup.BOOTSTRAP_LOGIN_BODY", parsed.setup.requests[0].store_body_as.?); try std.testing.expectEqual(@as(usize, 3), parsed.http.requests.len); try std.testing.expectEqual(HttpMethod.POST, parsed.http.requests[0].method); try std.testing.expectEqualStrings("content-type", parsed.http.requests[0].headers[0].key); try std.testing.expectEqualStrings("application/json", parsed.http.requests[0].headers[0].value); try std.testing.expectEqual(@as(u32, 250), parsed.http.requests[2].delay_before_ms); try std.testing.expectEqual(@as(usize, 2), parsed.thresholds.len); try std.testing.expectEqual(ThresholdMetric.http_request_duration_p99, parsed.thresholds[0].metric); try std.testing.expectEqual(ThresholdOperator.lte, parsed.thresholds[0].op); try std.testing.expectEqualStrings("login", parsed.thresholds[0].scope.request.?); try std.testing.expectEqual(ThresholdValue{ .duration = Duration.fromMillis(500) }, parsed.thresholds[0].value);}
test "parse threshold expressions with logical operators" { const source = \\[scenario] \\name = "expr" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" \\ \\[[thresholds]] \\scope = { request = "health" } \\expr = "check.pass_rate >= 1.0 && http.request.duration.p99 <= 500ms" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(config.ThresholdExpressionMode.all_of, parsed.thresholds[0].expression_mode.?); try std.testing.expectEqual(@as(usize, 2), parsed.thresholds[0].expression_clauses.len); try std.testing.expectEqual(ThresholdMetric.check_pass_rate, parsed.thresholds[0].expression_clauses[0].metric); try std.testing.expectEqual(ThresholdMetric.http_request_duration_p99, parsed.thresholds[0].expression_clauses[1].metric);}
test "parse simple mode config without wasm" { const source = \\[scenario] \\name = "simple-healthcheck" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 4 \\duration = "30s" \\warmup = "3s" \\thread_count = 3 \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" \\timeout_ms = 500 \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\op = "<=" \\value = "200ms" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(ScenarioMode.simple, parsed.scenario.mode()); try std.testing.expectEqual(WasmBackend.wamr, parsed.scenario.wasm_backend); try std.testing.expectEqual(@as(usize, 1), parsed.http.requests.len); try std.testing.expectEqual(Duration.fromSeconds(3).nanos, parsed.execution.warmup.nanos); try std.testing.expectEqual(Duration.fromMillis(100).nanos, parsed.execution.script_timeout.nanos); try std.testing.expectEqual(@as(u32, 0), parsed.execution.max_poisoned_workers); try std.testing.expectEqual(@as(u32, 3), parsed.execution.thread_count.?); try std.testing.expectEqual(@as(usize, 3), parsed.execution.effectiveThreadCount(8));}
test "parse grpc simple mode config using shared request schema" { const source = \\[scenario] \\name = "grpc-health" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 2 \\duration = "10s" \\ \\[http.defaults] \\cookie_jar = false \\headers = { x-env = "fixture" } \\ \\[[http.requests]] \\id = 1 \\name = "check" \\method = "POST" \\path = "/grpc.health.v1.Health/Check" \\body = "\x0a\x00" \\timeout_ms = 750 \\capture_body_max_bytes = 1024 ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(ScenarioMode.simple, parsed.scenario.mode()); try std.testing.expectEqual(config.Protocol.grpc, parsed.scenario.protocol); try std.testing.expectEqual(false, parsed.http.defaults.cookie_jar); try std.testing.expectEqualStrings("fixture", parsed.http.requests[0].headers[0].value); try std.testing.expectEqualStrings("/grpc.health.v1.Health/Check", parsed.http.requests[0].path); try std.testing.expectEqual(HttpMethod.POST, parsed.http.requests[0].method); try std.testing.expectEqual(@as(u32, 1024), parsed.http.requests[0].capture_body_max_bytes);}
test "http request defaults apply and request headers override by key" { const source = \\[scenario] \\name = "defaults" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\version = "1.1" \\max_connections = 12 \\ \\[http.defaults] \\headers = { authorization = "Bearer default", accept = "application/json" } \\connect_timeout_ms = 150 \\timeout_ms = 900 \\delay_before_ms = 25 \\pass_response_body = true \\capture_body_max_bytes = 2048 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" \\headers = { authorization = "Bearer override" } \\ \\[[http.requests]] \\id = 2 \\name = "two" \\method = "GET" \\path = "/two" \\connect_timeout_ms = 50 \\timeout_ms = 100 \\pass_response_body = false \\check_status_code = 200 \\check_body_contains = "ok" \\check_response_header = "x-trace-id" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(config.HttpVersion.http11, parsed.http.version); try std.testing.expectEqual(@as(?u32, 12), parsed.http.max_connections); try std.testing.expectEqual(@as(usize, 2), parsed.http.defaults.headers.len); try std.testing.expectEqual(@as(u32, 150), parsed.http.requests[0].connect_timeout_ms); try std.testing.expectEqual(@as(u32, 900), parsed.http.requests[0].timeout_ms); try std.testing.expectEqual(@as(u32, 25), parsed.http.requests[0].delay_before_ms); try std.testing.expectEqual(true, parsed.http.requests[0].pass_response_body); try std.testing.expectEqual(@as(u32, 2048), parsed.http.requests[0].capture_body_max_bytes); try std.testing.expectEqual(@as(usize, 2), parsed.http.requests[0].headers.len); try std.testing.expectEqualStrings("accept", parsed.http.requests[0].headers[0].key); try std.testing.expectEqualStrings("application/json", parsed.http.requests[0].headers[0].value); try std.testing.expectEqualStrings("authorization", parsed.http.requests[0].headers[1].key); try std.testing.expectEqualStrings("Bearer override", parsed.http.requests[0].headers[1].value);
try std.testing.expectEqual(@as(u32, 50), parsed.http.requests[1].connect_timeout_ms); try std.testing.expectEqual(@as(u32, 100), parsed.http.requests[1].timeout_ms); try std.testing.expectEqual(@as(u32, 25), parsed.http.requests[1].delay_before_ms); try std.testing.expectEqual(false, parsed.http.requests[1].pass_response_body); try std.testing.expectEqual(@as(u32, 2048), parsed.http.requests[1].capture_body_max_bytes); try std.testing.expectEqual(@as(?u16, 200), parsed.http.requests[1].check_status_code); try std.testing.expectEqualStrings("ok", parsed.http.requests[1].check_body_contains.?); try std.testing.expectEqualStrings("x-trace-id", parsed.http.requests[1].check_response_header.?); try std.testing.expectEqual(@as(usize, 2), parsed.http.requests[1].headers.len);}
test "reject non-positive http max_connections" { const source = \\[scenario] \\name = "defaults" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\max_connections = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
try std.testing.expectError(error.HttpMaxConnectionsMustBePositive, ScenarioConfig.parse(std.testing.allocator, source));}
test "parse plugin directory and plugin exporters" { const source = \\[scenario] \\name = "plugins" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[plugins] \\dir = "./samples/plugins/csv" \\ \\[http] \\transport_plugin = "custom-http" \\ \\[[exporters.plugins]] \\name = "csv" \\config = { path = "./out.csv" } \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqualStrings("./samples/plugins/csv", parsed.plugins.dir.?); try std.testing.expectEqualStrings("custom-http", parsed.http.transport_plugin.?); try std.testing.expectEqual(@as(usize, 1), parsed.exporters.plugins.len); try std.testing.expectEqualStrings("csv", parsed.exporters.plugins[0].name); try std.testing.expectEqualStrings("path", parsed.exporters.plugins[0].config[0].key);}
test "parse http version settings" { const source = \\[scenario] \\name = "http2" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\version = "auto" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(config.HttpVersion.auto, parsed.http.version);}
test "reject http2 without tls" { const source = \\[scenario] \\name = "http2" \\protocol = "http" \\target = "http://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\version = "2" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
try std.testing.expectError(error.Http2RequiresTls, ScenarioConfig.parse(std.testing.allocator, source));}
test "parseFile expands include directives before parsing" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup();
try tmp_dir.dir.writeFile(.{ .sub_path = "common.toml", .data = \\[http.defaults] \\headers = { accept = "application/json" } \\timeout_ms = 250 \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" , }); try tmp_dir.dir.writeFile(.{ .sub_path = "scenario.toml", .data = \\include = "./common.toml" \\ \\[scenario] \\name = "include" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" , });
const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/scenario.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path);
var parsed = try ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024); defer parsed.deinit();
try std.testing.expectEqual(@as(usize, 1), parsed.http.requests.len); try std.testing.expectEqual(@as(u32, 250), parsed.http.requests[0].timeout_ms); try std.testing.expectEqual(@as(usize, 1), parsed.http.requests[0].headers.len); try std.testing.expectEqualStrings("accept", parsed.http.requests[0].headers[0].key);}
test "parseFile rejects include cycles" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup();
try tmp_dir.dir.writeFile(.{ .sub_path = "a.toml", .data = \\include = "./b.toml" \\ \\[scenario] \\name = "a" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" , }); try tmp_dir.dir.writeFile(.{ .sub_path = "b.toml", .data = "include = \"./a.toml\"\n", });
const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/a.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path);
try std.testing.expectError(error.IncludeCycle, ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024));}
test "parseFile loads env_file values before placeholder resolution" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup();
try tmp_dir.dir.writeFile(.{ .sub_path = ".env", .data = \\API_HOST=env.example.internal \\TOKEN="secret-token" , }); try tmp_dir.dir.writeFile(.{ .sub_path = "scenario.toml", .data = \\env_file = "./.env" \\ \\[scenario] \\name = "env-file" \\protocol = "http" \\target = "https://${API_HOST}" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/v1/${iter.USER_ID}" \\headers = { authorization = "Bearer ${TOKEN}" } , });
const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/scenario.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path);
var parsed = try ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024); defer parsed.deinit();
try std.testing.expectEqualStrings("https://env.example.internal", parsed.scenario.target); try std.testing.expectEqualStrings("/v1/${iter.USER_ID}", parsed.http.requests[0].path); try std.testing.expectEqualStrings("Bearer secret-token", parsed.http.requests[0].headers[0].value);}
test "parseFile rejects invalid env_file entries" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup();
try tmp_dir.dir.writeFile(.{ .sub_path = ".env", .data = "NOT_VALID\n", }); try tmp_dir.dir.writeFile(.{ .sub_path = "scenario.toml", .data = \\env_file = "./.env" \\ \\[scenario] \\name = "env-file" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" , });
const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/scenario.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path);
try std.testing.expectError(error.InvalidEnvFileEntry, ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024));}
test "parse workflow execution timeout and poison settings" { const source = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\wasm_backend = "wasm3" \\recovery.window = "8s" \\recovery.max_recreates = 5 \\ \\[execution] \\mode = "constant-arrival-rate" \\rate = 25 \\duration = "30s" \\pre_allocated_vus = 4 \\max_vus = 8 \\script_timeout = "250ms" \\max_poisoned_workers = 2 \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(WasmBackend.wasm3, parsed.scenario.wasm_backend); try std.testing.expectEqual(Duration.fromSeconds(8).nanos, parsed.recovery.window.nanos); try std.testing.expectEqual(@as(u32, 5), parsed.recovery.max_recreates); try std.testing.expectEqual(Duration.fromMillis(250).nanos, parsed.execution.script_timeout.nanos); try std.testing.expectEqual(@as(u32, 2), parsed.execution.max_poisoned_workers);}
test "default recovery policy matches previous behavior" { const source = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(Duration.fromSeconds(5).nanos, parsed.recovery.window.nanos); try std.testing.expectEqual(@as(u32, 3), parsed.recovery.max_recreates);}
test "parse scheduler lag threshold metrics" { try std.testing.expectEqual( ThresholdMetric.scheduler_lag_avg, try literals.parseThresholdMetric("\"executor.scheduler_lag.avg\""), ); try std.testing.expectEqual( ThresholdMetric.scheduler_lag_max, try literals.parseThresholdMetric("\"executor.scheduler_lag.max\""), );}
test "parse transport timeout threshold metrics" { try std.testing.expectEqual( ThresholdMetric.http_transport_timeout_total, try literals.parseThresholdMetric("\"http.transport.timeout_total\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_timeout_rate, try literals.parseThresholdMetric("\"http.transport.timeout_rate\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_connect_timeout_total, try literals.parseThresholdMetric("\"http.transport.connect_timeout_total\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_connect_timeout_rate, try literals.parseThresholdMetric("\"http.transport.connect_timeout_rate\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_io_timeout_total, try literals.parseThresholdMetric("\"http.transport.io_timeout_total\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_io_timeout_rate, try literals.parseThresholdMetric("\"http.transport.io_timeout_rate\""), ); try std.testing.expectEqual( ThresholdMetric.check_failed_total, try literals.parseThresholdMetric("\"check.failed_total\""), ); try std.testing.expectEqual( ThresholdMetric.check_pass_rate, try literals.parseThresholdMetric("\"check.pass_rate\""), );}
test "reject unsupported wasm backend" { const source = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\wasm_backend = "unknown" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ;
try std.testing.expectError(error.UnsupportedWasmBackend, ScenarioConfig.parse(std.testing.allocator, source));}
test "resolve environment variables while preserving runtime placeholders" { const home = std.process.getEnvVarOwned(std.testing.allocator, "HOME") catch return error.SkipZigTest; defer std.testing.allocator.free(home);
const source = \\[scenario] \\name = "env" \\protocol = "http" \\target = "https://${HOME}" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "path" \\method = "GET" \\path = "/v1/${iter.USER_ID}" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
const expected_target = try std.fmt.allocPrint(std.testing.allocator, "https://{s}", .{home}); defer std.testing.allocator.free(expected_target);
try std.testing.expectEqualStrings(expected_target, parsed.scenario.target); try std.testing.expectEqualStrings("/v1/${iter.USER_ID}", parsed.http.requests[0].path);}
test "reject duplicate request ids" { const source = \\[scenario] \\name = "dup" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" \\ \\[[http.requests]] \\id = 1 \\name = "two" \\method = "GET" \\path = "/two" ;
try std.testing.expectError(error.DuplicateRequestId, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject plugin usage without plugin directory" { const source = \\[scenario] \\name = "plugin-missing-dir" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\transport_plugin = "custom-http" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ;
try std.testing.expectError(error.PluginDirectoryRequired, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject invalid request paths" { const source = \\[scenario] \\name = "bad-path" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "v1/no-leading-slash" ;
try std.testing.expectError(error.InvalidRequestPath, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject simple mode with multiple requests" { const source = \\[scenario] \\name = "simple-too-many" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "first" \\method = "GET" \\path = "/one" \\ \\[[http.requests]] \\id = 2 \\name = "second" \\method = "GET" \\path = "/two" ;
try std.testing.expectError(error.SimpleModeRequiresSingleRequest, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject grpc requests that do not use POST" { const source = \\[scenario] \\name = "grpc-bad-method" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http.defaults] \\cookie_jar = false \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "/grpc.health.v1.Health/Check" ;
try std.testing.expectError(error.GrpcRequiresPostMethod, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject grpc scenarios that enable cookie jars" { const source = \\[scenario] \\name = "grpc-cookie" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http.defaults] \\cookie_jar = true \\ \\[[http.requests]] \\id = 1 \\name = "check" \\method = "POST" \\path = "/grpc.health.v1.Health/Check" ;
try std.testing.expectError(error.GrpcCookieJarUnsupported, ScenarioConfig.parse(std.testing.allocator, source));}
test "parse grpc workflow mode with shared request schema" { const source = \\[scenario] \\name = "grpc-workflow" \\protocol = "grpc" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http.defaults] \\cookie_jar = false \\ \\[[http.requests]] \\id = 1 \\name = "check" \\method = "POST" \\path = "/grpc.health.v1.Health/Check" \\pass_response_body = true ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(ScenarioMode.workflow, parsed.scenario.mode()); try std.testing.expectEqual(config.Protocol.grpc, parsed.scenario.protocol); try std.testing.expectEqual(true, parsed.http.requests[0].pass_response_body);}
test "parse setup and shutdown timeouts" { const source = \\[scenario] \\name = "timeouts" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "5s" \\setup_timeout = "7s" \\shutdown_timeout = "45s" \\ \\[[setup.requests]] \\name = "bootstrap" \\method = "POST" \\path = "/bootstrap" \\timeout_ms = 1200 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(Duration.fromSeconds(7).nanos, parsed.execution.setup_timeout.nanos); try std.testing.expectEqual(Duration.fromSeconds(45).nanos, parsed.execution.shutdown_timeout.nanos); try std.testing.expectEqual(@as(u32, 1200), parsed.setup.requests[0].timeout_ms);}
test "parse ramping vus stages and exporters" { const source = \\[scenario] \\name = "ramping" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "ramping-vus" \\duration = "10s" \\ \\[[execution.stages]] \\target_vus = 2 \\duration = "3s" \\ \\[[execution.stages]] \\target_vus = 4 \\duration = "7s" \\ \\[http.defaults] \\cookie_jar = false \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\retry_max_attempts = 6 \\retry_max_elapsed = "45s" \\buffer_max_exports = 12 \\ \\[[http.requests]] \\id = 1 \\name = "echo" \\method = "POST" \\path = "/grpc.testing.Echo/Unary" ;
var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit();
try std.testing.expectEqual(Execution.Mode.ramping_vus, parsed.execution.mode); try std.testing.expectEqual(@as(usize, 2), parsed.execution.stages.len); try std.testing.expectEqual(@as(u32, 4), parsed.execution.maxRampingVus()); try std.testing.expectEqual(@as(u32, 0), parsed.execution.rampingTargetAt(0)); try std.testing.expectEqual(@as(u32, 1), parsed.execution.rampingTargetAt(Duration.fromSeconds(2).nanos)); try std.testing.expectEqualStrings("http://127.0.0.1:4318/v1/metrics", parsed.exporters.otlp.?.url); try std.testing.expectEqual(@as(u32, 6), parsed.exporters.otlp.?.retry_max_attempts); try std.testing.expectEqual(Duration.fromSeconds(45).nanos, parsed.exporters.otlp.?.retry_max_elapsed.nanos); try std.testing.expectEqual(@as(u32, 12), parsed.exporters.otlp.?.buffer_max_exports);}
test "reject warmup longer than duration" { const source = \\[scenario] \\name = "warmup" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\warmup = "2s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
try std.testing.expectError(error.WarmupExceedsDuration, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject invalid otlp retry settings" { const zero_attempts = \\[scenario] \\name = "otlp" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\retry_max_attempts = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.OtlpRetryMaxAttemptsMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_attempts));
const zero_elapsed = \\[scenario] \\name = "otlp" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\retry_max_elapsed = "0ms" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.OtlpRetryMaxElapsedMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_elapsed));
const zero_buffer = \\[scenario] \\name = "otlp" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\buffer_max_exports = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.OtlpBufferMaxExportsMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_buffer));}
test "reject zero script timeout" { const source = \\[scenario] \\name = "timeout" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\script_timeout = "0ms" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
try std.testing.expectError(error.ScriptTimeoutMustBePositive, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject zero execution thread count" { const source = \\[scenario] \\name = "threads" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\thread_count = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
try std.testing.expectError(error.ExecutionThreadCountMustBePositive, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject invalid recovery policy values" { const zero_window = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\recovery.window = "0ms" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.RecoveryWindowMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_window));
const zero_max = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\recovery.max_recreates = 0 \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.RecoveryMaxRecreatesMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_max));}
test "reject arrival rate configs where pre allocated vus exceed max" { const source = \\[scenario] \\name = "arrival-rate" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-arrival-rate" \\rate = 100 \\duration = "10s" \\pre_allocated_vus = 32 \\max_vus = 16 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
try std.testing.expectError(error.PreAllocatedVusExceedsMaxVus, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject setup request store keys outside setup namespace" { const source = \\[scenario] \\name = "setup" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[setup.requests]] \\name = "bootstrap" \\method = "POST" \\path = "/bootstrap" \\store_body_as = "iter.BAD" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ;
try std.testing.expectError(error.InvalidSetupStoreKey, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject thresholds with unknown request scopes" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\scope = { request = "unknown" } \\op = "<=" \\value = "200ms" ;
try std.testing.expectError(error.UnknownThresholdRequest, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject thresholds with unknown scenario scopes" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "http.error_rate" \\scope = { scenario = "other" } \\op = "<=" \\value = "0.01" ;
try std.testing.expectError(error.UnknownThresholdScenario, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject request-scoped iteration thresholds" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "iteration.success_rate" \\scope = { request = "known" } \\op = ">=" \\value = "1.0" ;
try std.testing.expectError(error.InvalidThresholdScope, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject thresholds with invalid value kind" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\op = "<=" \\value = "0.01" ;
try std.testing.expectError(error.InvalidThresholdValue, ScenarioConfig.parse(std.testing.allocator, source));}
test "parse byte size helper" { try std.testing.expectEqual(@as(u64, 4096), (try literals.parseByteSizeLiteral("4KiB")).bytes);}
test "parse ratio helper" { try std.testing.expectApproxEqAbs(@as(f64, 0.01), try literals.parseRatioLiteral("0.01"), 0.000001); try std.testing.expectError(error.RatioOutOfRange, literals.parseRatioLiteral("1.2"));}
test "reject template placeholders outside allowed namespaces" { const source = \\[scenario] \\name = "bad-template" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "/v1/${bad.KEY}" ;
try std.testing.expectError(error.InvalidTemplateVariable, ScenarioConfig.parse(std.testing.allocator, source));}
test "reject header values containing newlines" { const source = \\[scenario] \\name = "bad-header" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "/one" \\headers = { authorization = "Bearer one\nBearer two" } ;
try std.testing.expectError(error.InvalidHeaderValue, ScenarioConfig.parse(std.testing.allocator, source));}