Data

These data surfaces help a scenario keep track of state while it runs. Use them when payloads, resources, or partitions need to stay organized.

What this page helps you do

What this page helps you do

These data surfaces help a scenario keep track of state while it runs. Use them when payloads, resources, or partitions need to stay organized.

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 Data API surface in code.

Visual guide

Runtime data flow showing configuration, partition, invocation data, and metrics.
Runtime data scopes help steps choose values with the right lifetime and reporting visibility.

Guide

Invocation Data

LoadStrikeScenarioContext.Data is the per-invocation dictionary. Use it when one execution of the scenario needs to pass state from one part of the workflow to another.

Scenario Instance Data

LoadStrikeScenarioContext.ScenarioInstanceData stores shared objects for one scenario instance. It is the right place for resources that need to be reused across multiple invocations of the same scenario copy. Go keeps this data isolated by run, node, partition, scenario, and instance and releases it after scenario cleanup.

Random Helper

LoadStrikeScenarioContext.Random exposes Next, NextDouble, NextBytes, and Sample helpers when the workload needs controlled variation or deterministic sharding. TypeScript and JavaScript expose the same helper names in PascalCase on the public docs surface.

Cancellation Token

LoadStrikeScenarioContext.ScenarioCancellationToken exposes cancellation to active scenario work. In Go, use Done, Err, Deadline, and Value so long-running work can exit when request or run cancellation signals the token. StopScenario records the named stop intent and reason but does not itself signal this token.

Partition Data

LoadStrikeScenarioInitContext.ScenarioPartition exposes Number and Count so datasets can be split deterministically across clustered runs or multiple copies of the same scenario.

Init Configuration

LoadStrikeScenarioInitContext.CustomSettings and GlobalCustomSettings expose two distinct inputs. In Go, CustomSettings contains the decoded document supplied through LoadConfig, while GlobalCustomSettings is empty unless the application explicitly supplies global values. Use Get, Lookup, Len, or Values to read either set from init and cleanup hooks.

Go Callback Outcomes

Go init and cleanup callbacks receive custom and global settings plus current test, node, scenario, and partition metadata. Step callbacks receive those values plus ScenarioInstanceData for their scenario instance. Successful callback logs enter the configured run logger once. Active scenario callbacks can observe ScenarioCancellationToken when request or run cancellation signals it. StopScenario separately preserves the supplied scenario name and reason without signaling that token, and StopCurrentTest preserves its supplied reason.

Init Metrics

LoadStrikeScenarioInitContext.RegisterMetric(IMetric) lets you register custom counters and gauges during scenario initialization so thresholds, reports, and sinks all see the same metric set across supported SDKs.

SDK reference samples

Use these SDK samples to compare how Data 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.

Context Data

using LoadStrike;

private static readonly HttpClient SharedHttpClient = CreateHttpClient();

private static HttpClient CreateHttpClient()
{
    var handler = new SocketsHttpHandler
    {
        PooledConnectionLifetime = TimeSpan.FromMinutes(5),
        PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2),
        MaxConnectionsPerServer = 1000,
        AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
    };

    return new HttpClient(handler)
    {
        BaseAddress = new Uri("https://api.example.com"),
        Timeout = TimeSpan.FromSeconds(15)
    };
}

var scenario = LoadStrikeScenario.Create("submit-orders", async context =>
{
    context.ScenarioInstanceData["tenantId"] ??= "tenant-a";
    context.Data["orderId"] = $"ord-{context.InvocationNumber}";

    var step = await LoadStrikeStep.Run<string>("POST /orders", context, async () =>
    {
        var payload = new
        {
            orderId = (string)context.Data["orderId"],
            tenantId = (string)context.ScenarioInstanceData["tenantId"],
            amount = 49.95m
        };

        using var response = await SharedHttpClient.PostAsJsonAsync("/orders", payload);
        return response.IsSuccessStatusCode
            ? LoadStrikeResponse.Ok<string>(statusCode: ((int)response.StatusCode).ToString())
            : LoadStrikeResponse.Fail<string>(statusCode: ((int)response.StatusCode).ToString());
    });

    return step.AsReply();
})
.WithLoadSimulations(LoadStrikeSimulation.Inject(10, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(20)));

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

SharedHttpClient.Dispose();

Context fields a basic user should know

context.Data

Invocation-scoped dictionary. Use it for values that only need to live for the current execution of the scenario.

context.ScenarioInstanceData

Per-scenario-instance dictionary. Use it for shared clients, seeded data, or caches that must survive across multiple invocations of the same scenario copy. Go isolates the dictionary by run, node, partition, scenario, and instance and releases it after cleanup. For HTTP load steps, keep one shared client, session, or dispatcher here instead of constructing a fresh transport per request.

context.InvocationNumber

Monotonic invocation counter for the current scenario. It is a simple way to generate unique ids or branching behavior.

context.Random

Random generator provided by the runtime for payload variation or deterministic sharding.

Shared HTTP cleanup

Dispose or close the shared HTTP client, session, executor, or dispatcher when the run ends so pooled sockets are released cleanly.

context.NodeInfo / context.TestInfo / context.ScenarioInfo

Read-only metadata objects that describe where the scenario is running and what run it belongs to. Go init and cleanup callbacks receive these values plus partition metadata; step callbacks receive the same values for their actual work.

context.ScenarioCancellationToken

Cancellation token available to active scenario callbacks. Request or run cancellation signals it so long-running work can exit. StopScenario records its named stop intent and reason but does not itself signal this token. The token is not part of the init or cleanup context.

context.GetScenarioTimerTime()

Returns the elapsed scenario time seen by the current invocation.

context.StopScenario(...) / context.StopCurrentTest(...)

Use these helpers when runtime conditions should end a single scenario or the entire test early. Go preserves the supplied scenario name and reason for StopScenario and the supplied reason for StopCurrentTest.

initContext.CustomSettings / GlobalCustomSettings

Distinct configuration surfaces available during initialization and cleanup. In Go, CustomSettings holds the LoadConfig document, while GlobalCustomSettings stays empty unless the application explicitly supplies global values.

initContext.ScenarioPartition

Partition metadata for deterministic dataset sharding across copies or nodes.