Runtime Policy Controls

Runtime policies let your test code inspect or influence scenario and step execution when normal scenario logic is not enough.

What this page helps you do

What this page helps you do

Runtime policies let your test code inspect or influence scenario and step execution when normal scenario logic is not enough.

Who this is for

Teams controlling runtime behavior, tracking, reporting, licensing, or policy from code, JSON, or CLI settings.

Prerequisites

  • A scenario or run configuration that already works locally

By the end

The documented runtime setting or policy surface for this part of the product.

Use this page when

Use this page when runtime behavior changes because of configuration, policy, or execution settings rather than the scenario body itself.

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

What It Does

Runtime policies are user-defined callbacks that LoadStrike runs before and after scenarios and steps. Use them when you need last-mile execution rules such as skipping a scenario, tracing step boundaries, or recording custom control-flow decisions during a run.

Hooks Available

Every SDK supports the same logical hooks: shouldRunScenario, beforeScenario, afterScenario, beforeStep, and afterStep. All of them support async callbacks, and Java exposes the async forms with Async suffixes.

Error Handling

WithRuntimePolicyErrorMode defaults to Fail. Switch it to Continue when policy callback failures should be recorded in the run result but should not stop scenario or step execution. In Continue mode, a shouldRunScenario error still allows the scenario to run.

Run Result Output

Policy callback failures are written into LoadStrikeRunResult.PolicyErrors or policyErrors with the policy name, callback name, scenario name, step name, and message. That gives the team one place to review what the policy decided or where it failed.

What This Is Not

This page covers runtime callback hooks in your test code. Plan-enforced limits such as agent counts or timeout ceilings are separate and are described on the licensing and entitlements page.

Configuration samples

Use these samples to see how Runtime Policy Controls is configured in code, JSON, or CLI surfaces where this page documents them.

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

Runtime Policy Hooks

using LoadStrike;

sealed class OrdersRuntimePolicy : ILoadStrikeRuntimePolicy
{
    public Task<bool> ShouldRunScenario(string scenarioName) =>
        Task.FromResult(scenarioName != "health-check");

    public Task BeforeScenario(string scenarioName)
    {
        Console.WriteLine($"Starting {scenarioName}");
        return Task.CompletedTask;
    }

    public Task AfterScenario(string scenarioName, LoadStrikeScenarioRuntime _stats)
    {
        Console.WriteLine($"Finished {scenarioName}");
        return Task.CompletedTask;
    }

    public Task BeforeStep(string scenarioName, string stepName)
    {
        Console.WriteLine($"Before step {scenarioName}/{stepName}");
        return Task.CompletedTask;
    }

    public Task AfterStep(string scenarioName, string stepName, LoadStrikeReply _reply)
    {
        Console.WriteLine($"After step {scenarioName}/{stepName}");
        return Task.CompletedTask;
    }
}

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

            return step.AsReply();
        })
    .WithLoadSimulations(LoadStrikeSimulation.IterationsForConstant(1, 5));

var healthScenario = LoadStrikeScenario.Create(
        "health-check",
        _ => Task.FromResult(LoadStrikeResponse.Ok(statusCode: "200")))
    .WithLoadSimulations(LoadStrikeSimulation.IterationsForConstant(1, 1));

var result = LoadStrikeRunner.RegisterScenarios(ordersScenario, healthScenario)
    .WithRuntimePolicies(new OrdersRuntimePolicy())
    .WithRuntimePolicyErrorMode(LoadStrikeRuntimePolicyErrorMode.Continue)
    .WithRunnerKey("rkl_your_local_runner_key")
    .Run();

Console.WriteLine(result.PolicyErrors.Count);

Runtime policy hooks, settings, and result fields

WithRuntimePolicies(...) / withRuntimePolicies(...) / with_runtime_policies(...)

Registers one or more runtime policy objects on the runner or context. Each object can decide whether a scenario should run and can react before and after scenarios and steps.

WithRuntimePolicyErrorMode(Fail|Continue)

Controls what happens when a runtime policy callback throws. Fail stops the run. Continue records the error in the run result and lets the scenario or step continue.

shouldRunScenario(scenarioName)

Runs before a scenario starts and returns true or false. Return false to skip that scenario. If this callback throws while error mode is Continue, LoadStrike records the error and still allows the scenario to run.

beforeScenario(scenarioName)

Runs once before scenario execution begins. Use it for setup checks, tracing, or custom guard rails.

afterScenario(scenarioName, stats)

Runs after the scenario completes and receives the scenario runtime stats for that scenario. Use it when you want scenario-level post-processing.

beforeStep(scenarioName, stepName)

Runs before a step executes. Use it for lightweight timing markers, extra logging, or step-level allowlists.

afterStep(scenarioName, stepName, reply)

Runs after a step executes and receives the final reply object for that step. Use it when you need to inspect pass/fail status, status code, payload, or latency after the step finishes.

LoadStrikeRunResult.PolicyErrors / policyErrors

Contains one row per runtime policy callback failure. Each row includes policyName, callbackName, scenarioName, stepName, and message so the final run result explains what happened.

Async support

All SDKs support async runtime policy callbacks. Java exposes the async variants with Async suffixes such as shouldRunScenarioAsync and beforeStepAsync.

Runtime policy hooks are callbacks from your own test code. They are separate from licensing checks, which still validate plan limits such as agents or timeout ceilings before the run begins.