Documentation
¶
Overview ¶
Package pusher provides tools for load testing by repeatedly calling a given target function.
Index ¶
- Constants
- func Farm(rps int, duration time.Duration, workers []*Worker) error
- func Force(rps int, duration time.Duration, target Target, offers ...Offer) func(amount int) error
- func Work(rps int, duration time.Duration, target Target, offers ...Offer) error
- type Config
- type Gossip
- type Gossiper
- type Offer
- type Result
- type Target
- type When
- type Worker
Constants ¶
const ( // ErrInvalidRPS is returned when the provided requests-per-second (RPS) value is not positive. ErrInvalidRPS = ex.Error("invalid rps") // ErrMissingTarget is returned when a Worker is hired without a Target function. ErrMissingTarget = ex.Error("target is missing") // ErrWorkerIsBusy is returned when Work is called on a Worker that is already running. ErrWorkerIsBusy = ex.Error("worker is busy") // ErrInvalidOvertime is returned when Work is tried to run with a negative WithOvertime option. ErrInvalidOvertime = ex.Error("invalid overtime") )
Variables ¶
This section is empty.
Functions ¶
func Farm ¶
Farm runs a set of pre-configured workers in parallel. It uses an errgroup to manage their lifecycle, ensuring that if one worker fails, the context is canceled for all.
Types ¶
type Gossip ¶
Gossip represents a telemetry event generated during a Worker's operation. It contains the result, an error, and the task lifecycle stage.
func (*Gossip) AfterTarget ¶
AfterTarget returns true if the Gossip event occurred after the target execution.
func (*Gossip) BeforeTarget ¶
BeforeTarget returns true if the Gossip event occurred before the target execution.
type Gossiper ¶
type Gossiper interface {
// Listen runs in its own goroutine and processes events from the gossip channel.
Listen(ctx context.Context, worker *Worker, gossips <-chan *Gossip)
// Stop is called to gracefully shut down the listener and flush any buffered data.
Stop()
}
Gossiper defines the interface for listeners that process Gossip events. This allows plugging in various metric collectors, loggers, or reporters.
type Offer ¶
type Offer func(w *Worker)
Offer is a functional option for configuring a Worker. This pattern allows for flexible and extensible Worker initialization.
func WithGossips ¶
WithGossips configures a Worker with a set of event listeners.
func WithOvertime ¶
WithOvertime sets the maximum number of concurrently executing tasks that a Worker can run. It acts as a concurrency limiter.
type Target ¶
Target is a function that performs the work to be tested. It receives a context for cancellation and must return a Result and an error.
type When ¶
type When string
When defines the stage of a task's lifecycle at which a Gossip event is generated.
const ( // BeforeTarget is the moment just before the Target function is called. BeforeTarget When = "before-target" // AfterTarget is the moment just after the Target function returns. AfterTarget When = "after-target" // Canceled indicates that a scheduled task was skipped because the concurrency // limit was reached. Canceled When = "canceled" )
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is the core entity that generates a load by repeatedly calling the Target function at a specified rate (RPS) and concurrency limit.