Scenario

Define scenario behavior, lifecycle hooks, and execution options.

Core Construction

Use LoadStrikeScenario.Create(name, run) for executable scenarios or LoadStrikeScenario.Empty(name) when composing behavior through wrappers. Scenario name is required and must be unique in a run context.

Lifecycle Hooks

Use WithInit and WithClean to initialize and dispose shared resources per scenario instance. Typical usage includes HTTP clients, broker producers, browser runtimes, and cached test data.

Execution Controls

Use WithLoadSimulations to attach one or more load profiles, WithThresholds for pass/fail rules, WithWeight for cluster distribution influence, WithMaxFailCount for stop-on-failure boundaries, warmup controls (WithoutWarmUp/WithWarmUpDuration), and WithLicenseFeatures when a scenario needs to request explicit entitlement features. Each WithLoadSimulations or WithThresholds call replaces the current collection, so pass the full ordered set you want to keep.

Failure Behavior

WithRestartIterationOnFail controls whether iteration mode retries failed iterations. Pair it with runner-level WithRestartIterationMaxAttempts to limit additional restart attempts per iteration run; the initial execution still runs once before those restarts are consumed.

Feature Usage Samples

How to use snippets for Scenario.

Switch between C#, Java, Python, TypeScript, and JavaScript to see the native SDK shape for this sample.

Licensing note: every runnable sample requires a valid runner key via WithRunnerKey("...") or config key LoadStrike:RunnerKey.

Scenario

var scenario = LoadStrikeScenario.Create("orders", _ => Task.FromResult(LoadStrikeResponse.Ok()))
    .WithInit(_ => Task.CompletedTask)
    .WithClean(_ => Task.CompletedTask)
    .WithLoadSimulations(LoadStrikeSimulation.KeepConstant(2, TimeSpan.FromSeconds(15)));

Used APIs

Create

Build an executable scenario by providing the scenario name and the run delegate.

Empty

Start with a named shell scenario when wrappers or external configurators will add the runtime behavior later.

WithInit / WithClean

Open and close shared resources such as HTTP clients, brokers, browsers, or seeded test data per scenario instance.

WithLoadSimulations

Attach the ordered list of load profiles that should drive the scenario during the run.

WithThresholds

Add pass/fail rules that inspect scenario, step, or metric results while the test is running.

Each WithLoadSimulations or WithThresholds call replaces the current collection, so pass the full ordered set you want to keep.