Documentation
¶
Overview ¶
Package scenariorunner schedules repeated executions of an arbitrary callback across a fixed pool of virtual users (VUs), the way a load generator does.
It is deliberately engine-agnostic: it knows nothing about flows, HTTP or the rest of the runner packages. Callers supply an iteration function and a RunProfile; the scheduler guarantees at most RunProfile.VUs iterations are in flight at once and stops issuing new ones once a bound is reached.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidVUs = errors.New("scenariorunner: VUs must be >= 1") ErrNoStopCondition = errors.New("scenariorunner: profile must set Duration or MaxIterations") ErrNilIteration = errors.New("scenariorunner: iteration function must not be nil") )
Configuration errors returned by Run before any work is started.
Functions ¶
This section is empty.
Types ¶
type RunProfile ¶
type RunProfile struct {
// VUs is the number of concurrent workers. Must be >= 1.
VUs int
// Duration bounds the window during which new iterations are issued.
// Values <= 0 mean unbounded, in which case MaxIterations must be set.
Duration time.Duration
// MaxIterations bounds the total number of iterations issued. Values <= 0
// mean unbounded, in which case Duration must be set.
MaxIterations int64
}
RunProfile describes a constant-VU load profile.
type Summary ¶
type Summary struct {
// Iterations is the number of iterations that ran to completion.
Iterations int64
// Errors is how many of those iterations returned a non-nil error.
Errors int64
// Elapsed is the wall-clock time from start until the last worker exited.
Elapsed time.Duration
}
Summary reports what a scenario actually did.
func Run ¶
func Run(ctx context.Context, prof RunProfile, iter func(ctx context.Context, vu int, seq int64) error) (Summary, error)
Run executes iter repeatedly across prof.VUs workers until the profile's duration or iteration bound is reached, or ctx is canceled.
Each call receives the zero-based index of the worker running it and a scenario-wide sequence number; sequence numbers are handed out exactly once, contiguously from zero. At most prof.VUs calls are in flight at any moment.
Errors returned by iter are counted in Summary.Errors and never abort the scenario. Run stops issuing new iterations when a bound is hit or ctx is canceled, then drains the iterations already in flight before returning, so no worker outlives the call.
Run returns ctx.Err() if the context is done once the scenario ends, which is normally because cancellation stopped it early; the Summary still reports the work completed up to that point. Configuration problems are reported before any iteration runs, alongside a zero Summary.
A panic inside iter is not recovered: it crashes the process, as it would anywhere else in the engine.