cicada

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CheckMark   EmojiString = "\u2714"
	CrossMark               = "\u274C"
	FastForward             = "\u23E9"
)
View Source
const (
	STARTED   ScenarioStatus = "STARTED"
	SUCCEEDED                = "SUCCEEDED"
	FAILED                   = "FAILED"
	SKIPPED                  = "SKIPPED"
)

Variables

This section is empty.

Functions

func PrintMetricsAndResults

func PrintMetricsAndResults(r *TestResult, printer MetricPrinter)

Prints formatted test result and metrics for each scenario in test

func PrintResult

func PrintResult(r *TestResult)

Prints formatted test result

Types

type ArrivalRateOutput

type ArrivalRateOutput struct {
	Succeeded  int
	Failed     int
	FinalUsers int
	FinalRPS   int
	LastOutput interface{}
}

type BackendBuilder

type BackendBuilder interface {
	GetTestBackend() TestBackend
	GetTestEventBackend() TestEventBackend
	GetScenarioBackend(scenario *Scenario, state *State) ScenarioBackend
}

type ConstantArrivalRateConfig

type ConstantArrivalRateConfig struct {
	TargetRPS             int
	MinUsers              int
	MaxUsers              int
	Duration              time.Duration
	ResultMetricConverter ResultMetricConverter
}

type Dashboard

type Dashboard struct {
	// contains filtered or unexported fields
}

func NewDashboard

func NewDashboard(
	eventChannel <-chan *PoppedTestEvent,
	metricPrinter MetricPrinter,
) *Dashboard

func (*Dashboard) Display

func (d *Dashboard) Display()

Displays dashboard on console until test is finished

type DefaultScenarioSummary

type DefaultScenarioSummary struct {
	Succeeded  int
	Failed     int
	LastOutput interface{}
}

type EmojiString

type EmojiString string

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(config *EngineConfig) *Engine

func (*Engine) AddScenario

func (e *Engine) AddScenario(scenario *Scenario)

Adds scenario to engine

func (*Engine) RunTest

func (e *Engine) RunTest(timeout time.Duration) *RunningTest

Starts test with scenarios currently in engine

type EngineConfig

type EngineConfig struct {
	BackendBuilder BackendBuilder
}

type Event

type Event struct {
	Kind    string
	Payload interface{}
}

type LoadModel

type LoadModel = func(sc ScenarioCommands, state *State) (interface{}, error)

func ConstantArrivalRate

func ConstantArrivalRate(config *ConstantArrivalRateConfig) LoadModel

Runs scenario a fixed number of times per second and scales user pool to compensate for differences in actual rate

func NIterations

func NIterations(config *NIterationsConfig) LoadModel

Runs the scenario a set number of times. Use with the WhileHasWork user loop

func NSeconds

func NSeconds(config *NSecondsConfig) LoadModel

Runs a scenario for a set duration. Use with the WhileAlive user loop

func RunUntilSuccess

func RunUntilSuccess(timeout time.Duration) LoadModel

Runs scenario consecutively with a single user until a successful result is collected

Use the WhileHasWork user loop with this load model

func Threshold

func Threshold(config *ThresholdConfig) LoadModel

Continuously add users until threshold is reached

type LocalBackendBuilder

type LocalBackendBuilder struct {
	// contains filtered or unexported fields
}

func NewLocalBackendBuilder

func NewLocalBackendBuilder() *LocalBackendBuilder

func (*LocalBackendBuilder) GetScenarioBackend

func (b *LocalBackendBuilder) GetScenarioBackend(scenario *Scenario, state *State) ScenarioBackend

func (*LocalBackendBuilder) GetTestBackend

func (b *LocalBackendBuilder) GetTestBackend() TestBackend

func (*LocalBackendBuilder) GetTestEventBackend

func (b *LocalBackendBuilder) GetTestEventBackend() TestEventBackend

type LocalEventBus

type LocalEventBus struct {
	// contains filtered or unexported fields
}

func NewLocalEventBus

func NewLocalEventBus() *LocalEventBus

func (*LocalEventBus) Emit

func (b *LocalEventBus) Emit(kind string, payload interface{}) <-chan bool

func (*LocalEventBus) Subscribe

func (b *LocalEventBus) Subscribe(kind string, buffer ...int) *LocalEventBusSubscription

func (*LocalEventBus) Unsubscribe

func (b *LocalEventBus) Unsubscribe(subscriber *LocalEventBusSubscription)

type LocalEventBusSubscription

type LocalEventBusSubscription struct {
	// contains filtered or unexported fields
}

type LocalScenarioBackend

type LocalScenarioBackend struct {
	// contains filtered or unexported fields
}

func NewLocalScenarioBackend

func NewLocalScenarioBackend(
	scenario *Scenario,
	eventBus *LocalEventBus,
	state *State,
) *LocalScenarioBackend

func (*LocalScenarioBackend) AddMetric

func (b *LocalScenarioBackend) AddMetric(name string, value float64) error

func (*LocalScenarioBackend) DistributeWork

func (b *LocalScenarioBackend) DistributeWork(work int) error

func (*LocalScenarioBackend) GetUserResults

func (b *LocalScenarioBackend) GetUserResults() <-chan *PoppedUserResult

func (*LocalScenarioBackend) SendUserEvents

func (b *LocalScenarioBackend) SendUserEvents(kind string, payload interface{}) error

func (*LocalScenarioBackend) SetScenarioResult

func (b *LocalScenarioBackend) SetScenarioResult(output interface{}, exception error, timeTaken time.Duration) error

func (*LocalScenarioBackend) ShutdownChannel

func (b *LocalScenarioBackend) ShutdownChannel() <-chan error

func (*LocalScenarioBackend) StartUsers

func (b *LocalScenarioBackend) StartUsers(users int) error

func (*LocalScenarioBackend) Stop

func (b *LocalScenarioBackend) Stop()

func (*LocalScenarioBackend) StopUsers

func (b *LocalScenarioBackend) StopUsers(users int) error

type LocalScenarioCommands

type LocalScenarioCommands struct {
	// contains filtered or unexported fields
}

func NewScenarioCommands

func NewScenarioCommands(scenario *Scenario, backend ScenarioBackend) *LocalScenarioCommands

func (*LocalScenarioCommands) AddDatastoreMetric

func (sc *LocalScenarioCommands) AddDatastoreMetric(name string, value float64) error

Reports a metric value back to the running test

func (*LocalScenarioCommands) AddWork

func (sc *LocalScenarioCommands) AddWork(amount int) error

Allows users to perform specified amount of iterations if using a user loop that supports work.

func (*LocalScenarioCommands) GetLatestResults

func (sc *LocalScenarioCommands) GetLatestResults() <-chan *PoppedUserResult

Returns a channel that will give results from all users in scenario as they are collected

func (*LocalScenarioCommands) GetNumUsers

func (sc *LocalScenarioCommands) GetNumUsers() (int, error)

Gets number of current users in scenario

func (*LocalScenarioCommands) ScaleUsers

func (sc *LocalScenarioCommands) ScaleUsers(users int) error

Ensures specified number of users exist in scenario

func (*LocalScenarioCommands) SendUserEvents

func (sc *LocalScenarioCommands) SendUserEvents(kind string, payload interface{}) error

Sends signal to all user loops

func (*LocalScenarioCommands) ShutdownChannel

func (sc *LocalScenarioCommands) ShutdownChannel() <-chan error

Returns channel that will recieve an event if directed to shutdown by test

func (*LocalScenarioCommands) StartUsers

func (sc *LocalScenarioCommands) StartUsers(users int) error

Creates specified number of virtual users

func (*LocalScenarioCommands) StopUsers

func (sc *LocalScenarioCommands) StopUsers(users int) error

Stops specified number of virtual users

type LocalTestBackend

type LocalTestBackend struct {
	// contains filtered or unexported fields
}

func NewLocalTestBackend

func NewLocalTestBackend(eventBus *LocalEventBus) *LocalTestBackend

func (*LocalTestBackend) GetScenarioResults

func (b *LocalTestBackend) GetScenarioResults() <-chan *PoppedScenarioResult

func (*LocalTestBackend) SendTestEvent

func (b *LocalTestBackend) SendTestEvent(event *TestEvent) error

func (*LocalTestBackend) SetTestResult

func (b *LocalTestBackend) SetTestResult(result *TestResult) error

func (*LocalTestBackend) StartScenario

func (b *LocalTestBackend) StartScenario(scenario *Scenario, state *State) error

func (*LocalTestBackend) Stop

func (b *LocalTestBackend) Stop()

type LocalTestEventBackend

type LocalTestEventBackend struct {
	// contains filtered or unexported fields
}

func NewLocalTestEventBackend

func NewLocalTestEventBackend(eventBus *LocalEventBus) *LocalTestEventBackend

func (*LocalTestEventBackend) GetTestEvents

func (b *LocalTestEventBackend) GetTestEvents() <-chan *PoppedTestEvent

func (*LocalTestEventBackend) GetTestMetrics

func (b *LocalTestEventBackend) GetTestMetrics() <-chan *PoppedScenarioMetric

func (*LocalTestEventBackend) GetTestResult

func (b *LocalTestEventBackend) GetTestResult() <-chan *PoppedTestResult

func (*LocalTestEventBackend) Stop

func (b *LocalTestEventBackend) Stop()

type LocalUserBackend

type LocalUserBackend struct {
	// contains filtered or unexported fields
}

func NewLocalUserBackend

func NewLocalUserBackend(userID string, scenario *Scenario, eventBus *LocalEventBus) *LocalUserBackend

func (*LocalUserBackend) AddUserResult

func (b *LocalUserBackend) AddUserResult(result *UserResult) error

func (*LocalUserBackend) GetUserEvents

func (b *LocalUserBackend) GetUserEvents(kind string) <-chan *PoppedUserEvent

func (*LocalUserBackend) ShutdownChannel

func (b *LocalUserBackend) ShutdownChannel() <-chan error

func (*LocalUserBackend) Stop

func (b *LocalUserBackend) Stop()

type LocalUserCommands

type LocalUserCommands struct {
	Scenario *Scenario
	// contains filtered or unexported fields
}

func NewUserCommands

func NewUserCommands(id string, backend UserBackend, scenario *Scenario) *LocalUserCommands

func (*LocalUserCommands) GetEvents

func (uc *LocalUserCommands) GetEvents(kind string) <-chan *PoppedUserEvent

Returns channel that will recieve events sent by scenario to users

func (*LocalUserCommands) GetUserID

func (uc *LocalUserCommands) GetUserID() string

Gets ID of current user

func (*LocalUserCommands) GetWork

func (uc *LocalUserCommands) GetWork() <-chan *PoppedWork

Returns channel that will recieve work sent by scenario to this user

func (*LocalUserCommands) ReportResult

func (uc *LocalUserCommands) ReportResult(
	output interface{},
	exception error,

	timeTaken time.Duration,
) error

Sends result of scenario function to scenario

func (*LocalUserCommands) Run

func (uc *LocalUserCommands) Run(state *State) (interface{}, error)

Runs scenario function

func (*LocalUserCommands) ShutdownChannel

func (uc *LocalUserCommands) ShutdownChannel() <-chan error

Returns channel that will be notified of shutdown by scenario

type MetricAggregator

type MetricAggregator interface {
	GetScenarioMetricNames() map[string][]string
	GetCount(scenario, name string) int
	GetTotal(scenario, name string) float64
	GetMin(scenario, name string) float64
	GetMedian(scenario, name string) float64
	GetMax(scenario, name string) float64
	GetAverage(scenario, name string) float64
	GetRateAbove(scenario, name string, splitPoint float64) float64
	GetLast(scenario, name string) float64
}

type MetricPrinter

type MetricPrinter interface {
	GetPrintouts(scenario string) []string
}

type MetricsCollector

type MetricsCollector func(results []*UserResult) []*ScenarioMetric

type NIterationsConfig

type NIterationsConfig struct {
	Iterations            int
	Users                 int
	ResultMetricConverter ResultMetricConverter
}

type NSecondsConfig

type NSecondsConfig struct {
	Users                 int
	Duration              time.Duration
	ResultMetricConverter ResultMetricConverter
}

type PoppedScenarioMetric

type PoppedScenarioMetric struct {
	Metric *ScenarioMetric
	Err    error
}

type PoppedScenarioResult

type PoppedScenarioResult struct {
	Result *ScenarioResult
	Err    error
}

type PoppedTestEvent

type PoppedTestEvent struct {
	Event *TestEvent
	Err   error
}

type PoppedTestResult

type PoppedTestResult struct {
	Result *TestResult
	Err    error
}

type PoppedUserEvent

type PoppedUserEvent struct {
	Event *Event
	Err   error
}

type PoppedUserResult

type PoppedUserResult struct {
	Result *UserResult
	Err    error
}

type PoppedWork

type PoppedWork struct {
	Err error
}

type PrinterFunction

type PrinterFunction struct {
	Scenario string
	Name     string
	Printer  func(scenario, name string, agg MetricAggregator) string
}

type ResultAggregator

type ResultAggregator func(result *UserResult, previous interface{}) interface{}

Produces an aggregated result for all results gathered by scenario

type ResultMetricConverter

type ResultMetricConverter = func(output interface{}) map[string]float64

Takes an output and produces a map of metrics (name:value) derived from that output

type RunningTest

type RunningTest struct {
	// contains filtered or unexported fields
}

func NewRunningTest

func NewRunningTest(backend TestEventBackend) *RunningTest

func (*RunningTest) Events

func (rt *RunningTest) Events() <-chan *PoppedTestEvent

Returns channel that recieves status updates from test

func (*RunningTest) Metrics

func (rt *RunningTest) Metrics() <-chan *PoppedScenarioMetric

Returns channel that recieves metrics from test

func (*RunningTest) Result

func (rt *RunningTest) Result() <-chan *PoppedTestResult

Returns channel that recieves test result once test is finished

type ScaleOutFunction

type ScaleOutFunction func(currentUsers int) int

Determine new amount of users for iteration

type Scenario

type Scenario struct {
	Name         string
	Fn           ScenarioFunction
	Dependencies []*Scenario
	LoadModel    LoadModel
	UserLoop     UserLoop
}

func NewScenario

func NewScenario(name string, fn ScenarioFunction, options *ScenarioOptions) *Scenario

type ScenarioBackend

type ScenarioBackend interface {
	StartUsers(users int) error
	StopUsers(users int) error
	DistributeWork(work int) error
	SendUserEvents(kind string, payload interface{}) error
	GetUserResults() <-chan *PoppedUserResult
	SetScenarioResult(output interface{}, exception error, timeTaken time.Duration) error
	AddMetric(name string, value float64) error
	ShutdownChannel() <-chan error
	Stop()
}

type ScenarioCommands

type ScenarioCommands interface {
	GetNumUsers() (int, error)
	StartUsers(users int) error
	StopUsers(users int) error
	ScaleUsers(users int) error
	AddWork(amount int) error
	SendUserEvents(kind string, payload interface{}) error
	GetLatestResults() <-chan *PoppedUserResult
	AddDatastoreMetric(name string, value float64) error
	ShutdownChannel() <-chan error
}

type ScenarioFunction

type ScenarioFunction = func(state *State) (interface{}, error)

type ScenarioMetric

type ScenarioMetric struct {
	Scenario string
	Name     string
	Value    float64
}

type ScenarioOptions

type ScenarioOptions struct {
	Dependencies []*Scenario
	LoadModel    LoadModel
	UserLoop     UserLoop
}

type ScenarioResult

type ScenarioResult struct {
	ScenarioName string
	Result       interface{}
	Exception    error
	TimeTaken    time.Duration
}

type ScenarioStatus

type ScenarioStatus string

type StatAggregator

type StatAggregator struct {
	// contains filtered or unexported fields
}

func NewStatAggregator

func NewStatAggregator(
	metrics <-chan *PoppedScenarioMetric,
) *StatAggregator

func (*StatAggregator) GetAverage

func (agg *StatAggregator) GetAverage(scenario, name string) float64

func (*StatAggregator) GetCount

func (agg *StatAggregator) GetCount(scenario, name string) int

func (*StatAggregator) GetLast

func (agg *StatAggregator) GetLast(scenario, name string) float64

func (*StatAggregator) GetMax

func (agg *StatAggregator) GetMax(scenario, name string) float64

func (*StatAggregator) GetMedian

func (agg *StatAggregator) GetMedian(scenario, name string) float64

func (*StatAggregator) GetMin

func (agg *StatAggregator) GetMin(scenario, name string) float64

func (*StatAggregator) GetRateAbove

func (agg *StatAggregator) GetRateAbove(scenario, name string, splitPoint float64) float64

func (*StatAggregator) GetScenarioMetricNames

func (agg *StatAggregator) GetScenarioMetricNames() map[string][]string

func (*StatAggregator) GetTotal

func (agg *StatAggregator) GetTotal(scenario, name string) float64

type StatPrinter

type StatPrinter struct {
	// contains filtered or unexported fields
}

func NewStatPrinter

func NewStatPrinter(config *StatPrinterConfig) *StatPrinter

func (*StatPrinter) AddPrinterFunction

func (sp *StatPrinter) AddPrinterFunction(pf *PrinterFunction)

func (*StatPrinter) GetPrintouts

func (sp *StatPrinter) GetPrintouts(scenario string) []string

Returns list of formatted strings for printer functions and metrics that belong to this scenario

type StatPrinterConfig

type StatPrinterConfig struct {
	MetricAggregator MetricAggregator
	PrinterFunctions []*PrinterFunction
}

type State

type State struct {
	// contains filtered or unexported fields
}

func NewState

func NewState() *State

func (*State) GetResult

func (c *State) GetResult(name string) *ScenarioResult

Gets result of a completed scenario

type TestBackend

type TestBackend interface {
	StartScenario(scenario *Scenario, state *State) error
	GetScenarioResults() <-chan *PoppedScenarioResult
	SendTestEvent(event *TestEvent) error
	SetTestResult(result *TestResult) error
	Stop()
}

type TestEvent

type TestEvent struct {
	Text             string
	ScenarioStatuses map[string]ScenarioStatus
}

type TestEventBackend

type TestEventBackend interface {
	GetTestEvents() <-chan *PoppedTestEvent
	GetTestResult() <-chan *PoppedTestResult
	GetTestMetrics() <-chan *PoppedScenarioMetric
	Stop()
}

type TestResult

type TestResult struct {
	State            *State
	ScenarioStatuses map[string]ScenarioStatus
}

type ThresholdConfig

type ThresholdConfig struct {
	StartingUsers         int
	ScalingPeriod         time.Duration
	ScaleOutFunction      ScaleOutFunction
	ResultMetricConverter ResultMetricConverter
	ResultAggregator      ResultAggregator
	ThresholdFunction     ThresholdFunction
}

type ThresholdFunction

type ThresholdFunction func(stats *ThresholdOutput) bool

Returns true if test has reached threshold yet based on provided stats

type ThresholdOutput

type ThresholdOutput struct {
	ResultsCollected int64
	Rps              float64
	SuccessRate      float64
	Aggregate        interface{}
	FinalUsers       int
}

type UserBackend

type UserBackend interface {
	GetUserEvents(kind string) <-chan *PoppedUserEvent
	AddUserResult(result *UserResult) error
	ShutdownChannel() <-chan error
	Stop()
}

type UserCommands

type UserCommands interface {
	GetUserID() string
	GetEvents(kind string) <-chan *PoppedUserEvent
	GetWork() <-chan *PoppedWork
	Run(state *State) (interface{}, error)
	ShutdownChannel() <-chan error
	ReportResult(
		output interface{},
		exception error,

		timeTaken time.Duration,
	) error
}

type UserLoop

type UserLoop = func(uc UserCommands, state *State)

func WhileAlive

func WhileAlive() UserLoop

Run scenario function continuously until deactivated by load model

func WhileHasWork

func WhileHasWork() UserLoop

Run scenario function only when directed to by load model

type UserResult

type UserResult struct {
	Output    interface{}
	Exception error
	// Logs      string
	TimeTaken time.Duration
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL