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)));
import com.loadstrike.runtime.LoadStrikeRuntime.LoadStrikeResponse;
import com.loadstrike.runtime.LoadStrikeRuntime.LoadStrikeScenario;
import com.loadstrike.runtime.LoadStrikeRuntime.LoadStrikeSimulation;
import java.util.concurrent.CompletableFuture;
var scenario = LoadStrikeScenario
.create("orders", context -> LoadStrikeResponse.ok())
.withInitAsync(initContext -> CompletableFuture.completedFuture(null))
.withCleanAsync(cleanContext -> CompletableFuture.completedFuture(null))
.withLoadSimulations(LoadStrikeSimulation.keepConstant(2, 15d));
from loadstrike_sdk import LoadStrikeResponse, LoadStrikeScenario, LoadStrikeSimulation
scenario = (
LoadStrikeScenario.create("orders", lambda _context: LoadStrikeResponse.ok())
.with_init(lambda _init_context: None)
.with_clean(lambda _clean_context: None)
.with_load_simulations(LoadStrikeSimulation.keep_constant(2, 15))
)
import { LoadStrikeResponse, LoadStrikeScenario, LoadStrikeSimulation } from "@loadstrike/loadstrike-sdk";
const scenario = LoadStrikeScenario
.create("orders", async () => LoadStrikeResponse.ok())
.withInit(async () => {})
.withClean(async () => {})
.withLoadSimulations(LoadStrikeSimulation.keepConstant(2, 15));
const { LoadStrikeResponse, LoadStrikeScenario, LoadStrikeSimulation } = require("@loadstrike/loadstrike-sdk");
const scenario = LoadStrikeScenario
.create("orders", async () => LoadStrikeResponse.ok())
.withInit(async () => {})
.withClean(async () => {})
.withLoadSimulations(LoadStrikeSimulation.keepConstant(2, 15));
Used APIs
Build an executable scenario by providing the scenario name and the run delegate.
Start with a named shell scenario when wrappers or external configurators will add the runtime behavior later.
Open and close shared resources such as HTTP clients, brokers, browsers, or seeded test data per scenario instance.
Attach the ordered list of load profiles that should drive the scenario during the run.
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.