/** * A `ScenarioWorker` is one virtual user. It owns one Playwright * context (clean cookies / storage isolated from other workers), * loops its scenario until either the deadline or its iteration cap * fires, and accumulates timing samples + errors for the runner to * aggregate. * * Each worker creates its context lazily on `run()` and tears it down * on `stop()`. The browser itself is owned by the runner and shared * across workers — one Chromium process for the whole load run keeps * memory bounded at ~10× lower than per-worker-browser. */ import type { Browser, BrowserContext } from "playwright"; import { type NetworkSample } from "./sampler.js"; import type { Scenario, ThinkTime } from "./types.js"; import type { Invariant } from "../types.js"; export interface WorkerStepSample { scenarioName: string; stepName: string; durationMs: number; success: boolean; /** Worker-local iteration counter (0-based). */ iteration: number; /** Wall-clock timestamp at step end. */ timestamp: number; } export interface WorkerIterationSample { scenarioName: string; durationMs: number; success: boolean; iteration: number; timestamp: number; } export interface WorkerError { scenarioName: string; stepName: string; iteration: number; timestamp: number; message: string; } export interface WorkerSamples { steps: WorkerStepSample[]; iterations: WorkerIterationSample[]; network: NetworkSample[]; errors: WorkerError[]; /** * Snapshot of `window.__chaosbringerRuntimeStats` captured just * before the worker's BrowserContext closes. Indexed by stringified * compiled-runtime-fault id (same shape `mergeRuntimeStats` consumes). * Empty when runtime faults weren't configured for this worker. */ runtimeFaultStats: Record; } export interface WorkerOptions { workerIndex: number; scenario: Scenario; baseUrl: string; defaultThinkTime?: ThinkTime; viewport?: { width: number; height: number; }; storageState?: string; invariants?: ReadonlyArray; maxIterations?: number; /** Stop ASAP when this resolves (deadline reached). */ shouldStop: () => boolean; /** * Pre-context hook — lets the runner wire in network fault routes / * runtime fault init-scripts before any scenario code runs. Called * once per worker on context create. */ onContextCreated?: (context: BrowserContext) => Promise; } export declare class ScenarioWorker { private readonly opts; private context; private page; private sampler; private readonly samples; private iteration; constructor(opts: WorkerOptions); get workerIndex(): number; run(browser: Browser): Promise; private runIteration; private invariantState; private runInvariants; private recordError; } //# sourceMappingURL=worker.d.ts.map