Asserts And Thresholds

Thresholds are the pass or fail rules for a run. Use them when the test needs to decide whether the observed behavior was acceptable.

What this page helps you do

What this page helps you do

Thresholds are the pass or fail rules for a run. Use them when the test needs to decide whether the observed behavior was acceptable.

Who this is for

Engineers writing or reviewing scenario code in one of the supported SDKs.

Prerequisites

  • A scenario or runtime surface you want to wire correctly in code

By the end

The exact SDK surface you need for this part of the runtime.

Use this page when

Use this reference when you already know the workflow and need the exact Asserts And Thresholds API surface in code.

Visual guide

Sequence diagram showing how a LoadStrike workflow moves from setup to report output.
This page fits into the same setup, run, correlate, and report flow as the rest of the public LoadStrike runtime.

Guide

Scenario Threshold

Use the scenario-threshold helper when the rule should evaluate the overall scenario, such as RPS, error rate, or latency percentiles. Go now exposes the same `.NET`-named helper through LoadStrikeThreshold{}.CreateScenario(...), and the older package-level CreateScenarioThreshold(...) helper remains a valid alias over the same underlying threshold contract.

Step Threshold

Use the step-threshold helper when one named step needs its own quality gate separate from the rest of the scenario. Go now exposes LoadStrikeThreshold{}.CreateStep(stepName, ...), and the older package-level CreateStepThreshold(stepName, ...) helper still maps to the same threshold builder logic.

Metric Threshold

Use the metric-threshold helper when the decision should be based on collected counters or gauges rather than scenario or step aggregates. Go now exposes LoadStrikeThreshold{}.CreateMetric(...), and the older package-level CreateMetricThreshold(...) helper still maps to the same metric-threshold contract.

Predicate Helper Parity

Predicate threshold helpers are available across the public SDKs now. `.NET` exposes ScenarioPredicate, StepPredicate, and MetricPredicate as aliases over its predicate builders, Go exposes the same `.NET`-named methods on LoadStrikeThreshold{}, and Java exposes scenarioPredicate, stepPredicate, and metricPredicate plus matching Pascal-case aliases.

Predicate Contract

Threshold callbacks are predicates over scenario, step, or metric stats. Return true when the rule passes and false when it fails. If a predicate throws, LoadStrike records that evaluation as a failed threshold result so the final artifact still shows which checkExpression failed and why.

Threshold Fields

All threshold creators support abortWhenErrorCount and startCheckAfter when you need controlled evaluation timing or an early-stop rule once enough failures have accumulated.

Threshold Result Surface

Final results keep every evaluation in thresholdResults or ThresholdResults, while failedThresholds exposes the top-level failed count for quick automation checks. The HTML report also renders a Thresholds tab when threshold evaluations were recorded, so the same pass or fail evidence is visible in both CI and report review.

SDK reference samples

Use these SDK samples to compare how Asserts And Thresholds is exposed across the supported languages before you wire it into a full scenario.

If you run these examples locally, add a valid runner key before execution starts. Set it with WithRunnerKey("...") or the config key LoadStrike:RunnerKey.

Thresholds

using LoadStrike;

var scenario = LoadStrikeScenario.Create("submit-orders", async context =>
    {
        var step = await LoadStrikeStep.Run<string>(
            "POST /orders",
            context,
            () => Task.FromResult(LoadStrikeResponse.Ok<string>(statusCode: "200")));

        return step.AsReply();
    })
    .WithThresholds(
        LoadStrikeThreshold.CreateScenario(stats => stats.Fail.Request.Percent < 2),
        LoadStrikeThreshold.CreateStep("POST /orders", stats => stats.Ok.Latency.Percent95 < 500)
    )
    .WithLoadSimulations(LoadStrikeSimulation.Inject(10, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(20)));

LoadStrikeRunner.RegisterScenarios(scenario)
    .WithRunnerKey("rkl_your_local_runner_key")
    .Run();

Threshold builders and threshold parameters

CreateScenario(checkScenario, abortWhenErrorCount?, startCheckAfter?)

Evaluates whole-scenario stats. Use it for latency, request rate, or fail-percent rules that apply to the overall workload.

CreateStep(stepName, checkStep, abortWhenErrorCount?, startCheckAfter?)

Evaluates one named step. stepName must match the exact step name used in LoadStrikeStep.Run.

CreateMetric(checkMetric, abortWhenErrorCount?, startCheckAfter?)

Evaluates custom counters and gauges that were registered during scenario initialization.

Predicate callbacks

Threshold delegates are predicates. Return true when the rule passes and false when it fails. If the predicate throws, the failure is still captured in the final threshold results.

abortWhenErrorCount

Optional early-stop control. Use it when a repeated threshold failure should abort quickly instead of letting the run continue indefinitely.

startCheckAfter

Optional delay before threshold evaluation begins. This is useful when you want to ignore warmup or early transient behavior.

LoadStrikeRunResult.thresholdResults / ThresholdResults / failedThresholds

The final result keeps the full threshold evaluation rows plus the aggregate failed-threshold count, so CI and human report review can read the same pass or fail evidence.

RegisterMetric(IMetric)

Register custom metrics in WithInit so threshold evaluation, reports, and sinks all observe the same metric set.