Documentation ¶
Overview ¶
Package servicetest contains tools and tests for the service package.
Please do not use any of the types exposed by this package.
To run the tests with code coverage, ensure you pass the packages to 'go test' like so:
-coverpkg=github.com/shabbyrobe/go-service
Because there are so many pieces needed to test all this stuff, the files are rather irritatingly named test_blahblah_test.go. Maybe it can be broken into more packages so this isn't necessary but it'll do for now.
Index ¶
- func CauseListSorted(err error) (out []error)
- func ErrorListSorted(err error) (out []error)
- func FuzzErrs(err error) (out []string)
- func ListErrs(err error) (out []error)
- type BlockingService
- type ErrorCounter
- func (e *ErrorCounter) Add(err error)
- func (e *ErrorCounter) Clone() *ErrorCounter
- func (e *ErrorCounter) Failed() (out int)
- func (e *ErrorCounter) MarshalJSON() ([]byte, error)
- func (e *ErrorCounter) Percent() (out float64)
- func (e *ErrorCounter) Succeeded() (out int)
- func (e *ErrorCounter) Total() (out int)
- type ErrorService
- type FloatRange
- type FloatRangeMaker
- type FuzzError
- type FuzzServiceStats
- func (s *FuzzServiceStats) AddServiceEnd(err error)
- func (s *FuzzServiceStats) AddServiceError(err error)
- func (s *FuzzServiceStats) Clone() *FuzzServiceStats
- func (s *FuzzServiceStats) Errors() (out []FuzzError)
- func (s *FuzzServiceStats) Map() map[string]interface{}
- func (s *FuzzServiceStats) ServiceEnded() (out int)
- type FuzzStats
- func (s *FuzzStats) AddRunnersCurrent(n int)
- func (s *FuzzStats) AddRunnersHalted(n int)
- func (s *FuzzStats) AddRunnersStarted(n int)
- func (s *FuzzStats) AddServicesCurrent(n int)
- func (s *FuzzStats) AddStateCheckResult(state service.State)
- func (s *FuzzStats) AddTick()
- func (s *FuzzStats) Clone() *FuzzStats
- func (s *FuzzStats) Ends() int
- func (s *FuzzStats) Errors() (out []FuzzError)
- func (s *FuzzStats) GetRunnersCurrent() int
- func (s *FuzzStats) GetRunnersHalted() int
- func (s *FuzzStats) GetRunnersStarted() int
- func (s *FuzzStats) GetServicesCurrent() int
- func (s *FuzzStats) GetTick() int
- func (s *FuzzStats) Map() map[string]interface{}
- func (s *FuzzStats) MarshalJSON() ([]byte, error)
- func (s *FuzzStats) Start()
- func (s *FuzzStats) Starts() int
- type IntRange
- type IntRangeMaker
- type Listener
- type ListenerCollector
- func (t *ListenerCollector) EndWaiter(svc *service.Service, cap int) Waiter
- func (t *ListenerCollector) Ends(svc *service.Service) (out []ListenerCollectorEnd)
- func (t *ListenerCollector) ErrWaiter(svc *service.Service, cap int) Waiter
- func (t *ListenerCollector) Errs(svc *service.Service) (out []error)
- func (t *ListenerCollector) OnServiceEnd(stage service.Stage, svc *service.Service, err error)
- func (t *ListenerCollector) OnServiceError(stage service.Stage, svc *service.Service, err error)
- func (t *ListenerCollector) RunnerOptions(opts ...service.RunnerOption) []service.RunnerOption
- func (t *ListenerCollector) StateWaiter(svc *service.Service, cap int) StateWaiter
- type ListenerCollectorEnd
- type RunnerFuzzer
- type RunnerFuzzerBuilder
- type RunnerSource
- type ServiceRunnerSource
- type StateWaiter
- type TimeRange
- type TimeRangeMaker
- type TimedService
- type UnhaltableService
- type Waiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CauseListSorted ¶
func ErrorListSorted ¶
Types ¶
type BlockingService ¶
type BlockingService struct { StartFailure error StartLimit int StartDelay time.Duration RunFailure error HaltDelay time.Duration // contains filtered or unexported fields }
BlockingService is a testing service that does no work, but blocks until it is Halted.
func (*BlockingService) Halts ¶
func (d *BlockingService) Halts() int
func (*BlockingService) Init ¶
func (d *BlockingService) Init() *BlockingService
func (*BlockingService) Starts ¶
func (d *BlockingService) Starts() int
type ErrorCounter ¶
type ErrorCounter struct {
// contains filtered or unexported fields
}
func (*ErrorCounter) Add ¶
func (e *ErrorCounter) Add(err error)
func (*ErrorCounter) Clone ¶
func (e *ErrorCounter) Clone() *ErrorCounter
func (*ErrorCounter) Failed ¶
func (e *ErrorCounter) Failed() (out int)
func (*ErrorCounter) MarshalJSON ¶
func (e *ErrorCounter) MarshalJSON() ([]byte, error)
func (*ErrorCounter) Percent ¶
func (e *ErrorCounter) Percent() (out float64)
func (*ErrorCounter) Succeeded ¶
func (e *ErrorCounter) Succeeded() (out int)
func (*ErrorCounter) Total ¶
func (e *ErrorCounter) Total() (out int)
type ErrorService ¶
type ErrorService struct { Name service.Name StartDelay time.Duration // contains filtered or unexported fields }
func (*ErrorService) Init ¶
func (d *ErrorService) Init() *ErrorService
func (*ErrorService) ServiceName ¶
func (d *ErrorService) ServiceName() service.Name
type FloatRange ¶
func (FloatRange) Rand ¶
func (t FloatRange) Rand() float64
type FloatRangeMaker ¶
type FloatRangeMaker struct { Min FloatRange Max FloatRange }
func (FloatRangeMaker) Rand ¶
func (t FloatRangeMaker) Rand() FloatRange
type FuzzServiceStats ¶
type FuzzServiceStats struct { ServiceHalt *ErrorCounter ServiceStart *ErrorCounter ServiceRestart *ErrorCounter // contains filtered or unexported fields }
func NewFuzzServiceStats ¶
func NewFuzzServiceStats() *FuzzServiceStats
func (*FuzzServiceStats) AddServiceEnd ¶
func (s *FuzzServiceStats) AddServiceEnd(err error)
func (*FuzzServiceStats) AddServiceError ¶
func (s *FuzzServiceStats) AddServiceError(err error)
func (*FuzzServiceStats) Clone ¶
func (s *FuzzServiceStats) Clone() *FuzzServiceStats
func (*FuzzServiceStats) Errors ¶
func (s *FuzzServiceStats) Errors() (out []FuzzError)
func (*FuzzServiceStats) Map ¶
func (s *FuzzServiceStats) Map() map[string]interface{}
func (*FuzzServiceStats) ServiceEnded ¶
func (s *FuzzServiceStats) ServiceEnded() (out int)
type FuzzStats ¶
type FuzzStats struct { Duration time.Duration Seed int64 Tick int32 RunnersStarted int32 RunnersCurrent int32 RunnersHalted int32 ServicesCurrent int32 Service *FuzzServiceStats StateCheckResults map[service.State]int // contains filtered or unexported fields }
func NewFuzzStats ¶
func NewFuzzStats() *FuzzStats
func (*FuzzStats) AddRunnersCurrent ¶
func (*FuzzStats) AddRunnersHalted ¶
func (*FuzzStats) AddRunnersStarted ¶
func (*FuzzStats) AddServicesCurrent ¶
func (*FuzzStats) AddStateCheckResult ¶
func (*FuzzStats) GetRunnersCurrent ¶
func (*FuzzStats) GetRunnersHalted ¶
func (*FuzzStats) GetRunnersStarted ¶
func (*FuzzStats) GetServicesCurrent ¶
func (*FuzzStats) MarshalJSON ¶
type IntRangeMaker ¶
func (IntRangeMaker) Rand ¶
func (t IntRangeMaker) Rand() IntRange
type ListenerCollector ¶
type ListenerCollector struct {
// contains filtered or unexported fields
}
ListenerCollector allows you to test things that make use of service.Runner's listener.
Please do not use it for any other purpose, it is only built to be useful in a test.
func NewListenerCollector ¶
func NewListenerCollector() *ListenerCollector
func (*ListenerCollector) EndWaiter ¶
func (t *ListenerCollector) EndWaiter(svc *service.Service, cap int) Waiter
func (*ListenerCollector) Ends ¶
func (t *ListenerCollector) Ends(svc *service.Service) (out []ListenerCollectorEnd)
func (*ListenerCollector) ErrWaiter ¶
func (t *ListenerCollector) ErrWaiter(svc *service.Service, cap int) Waiter
func (*ListenerCollector) Errs ¶
func (t *ListenerCollector) Errs(svc *service.Service) (out []error)
func (*ListenerCollector) OnServiceEnd ¶
func (*ListenerCollector) OnServiceError ¶
func (*ListenerCollector) RunnerOptions ¶
func (t *ListenerCollector) RunnerOptions(opts ...service.RunnerOption) []service.RunnerOption
func (*ListenerCollector) StateWaiter ¶
func (t *ListenerCollector) StateWaiter(svc *service.Service, cap int) StateWaiter
type ListenerCollectorEnd ¶
type RunnerFuzzer ¶
type RunnerFuzzer struct { RunnerSource RunnerSource Duration time.Duration Tick time.Duration RunnerLimit int ServiceLimit int RunnerCreateChance float64 // This is a wonderful mess-maker. It will attempt, in a goroutine, // to halt every service it finds in a runner. It does NOT a happy // path make. RunnerHaltChance float64 ServiceCreateChance float64 // Chance that the fuzzer will randomly halt a service, regardless of // whether it is an appropriate time: ServiceHaltChance float64 ServiceStartFailureChance float64 ServiceRunFailureChance float64 // Chance that the fuzzer will attempt to restart a random service at a // random moment. ServiceRestartChance float64 // Chance that a service started by the fuzzer will be restartable. ServiceRestartableChance float64 // The amount of time the service will take before it calls ctx.Ready(). ServiceStartTime TimeRange // The amount of time the fuzzer will wait for the service to start. If // this is shorter than ServiceStartTime, the fuzzer will experience start // failures. StartWaitTimeout TimeRange ServiceRunTime TimeRange ServiceHaltAfter TimeRange ServiceHaltDelay TimeRange ServiceHaltTimeout TimeRange StateCheckChance float64 Stats *FuzzStats `json:"-"` // contains filtered or unexported fields }
func (*RunnerFuzzer) Init ¶
func (r *RunnerFuzzer) Init(tt assert.T)
func (*RunnerFuzzer) OnServiceEnd ¶
func (r *RunnerFuzzer) OnServiceEnd() service.OnEnd
func (*RunnerFuzzer) OnServiceError ¶
func (r *RunnerFuzzer) OnServiceError() service.OnError
func (*RunnerFuzzer) Run ¶
func (r *RunnerFuzzer) Run(tt assert.T)
type RunnerFuzzerBuilder ¶
type RunnerFuzzerBuilder struct { StateCheckChance FloatRange RunnerCreateChance FloatRange RunnerHaltChance FloatRange ServiceCreateChance FloatRange StartWaitChance FloatRange ServiceStartFailureChance FloatRange ServiceRunFailureChance FloatRange ServiceStartTime TimeRangeMaker StartWaitTimeout TimeRangeMaker ServiceRunTime TimeRangeMaker ServiceHaltAfter TimeRangeMaker ServiceHaltDelay TimeRangeMaker ServiceHaltTimeout TimeRangeMaker }
func (RunnerFuzzerBuilder) Next ¶
func (f RunnerFuzzerBuilder) Next(dur time.Duration) *RunnerFuzzer
type RunnerSource ¶
type ServiceRunnerSource ¶
type ServiceRunnerSource struct{}
func (*ServiceRunnerSource) CanCreateRunner ¶
func (srs *ServiceRunnerSource) CanCreateRunner() bool
func (*ServiceRunnerSource) CanHaltRunner ¶
func (srs *ServiceRunnerSource) CanHaltRunner() bool
func (*ServiceRunnerSource) CreateRunner ¶
func (srs *ServiceRunnerSource) CreateRunner(l Listener) service.Runner
func (*ServiceRunnerSource) End ¶
func (srs *ServiceRunnerSource) End()
func (*ServiceRunnerSource) FirstRunner ¶
func (srs *ServiceRunnerSource) FirstRunner(l Listener) service.Runner
type StateWaiter ¶
type StateWaiter interface { TakeN(n int, timeout time.Duration) []service.StateChange Take(timeout time.Duration) *service.StateChange C() <-chan service.StateChange }
type TimeRangeMaker ¶
func (TimeRangeMaker) Rand ¶
func (t TimeRangeMaker) Rand() TimeRange
type TimedService ¶
type TimedService struct { StartFailure error StartDelay time.Duration StartLimit int RunFailure error RunTime time.Duration HaltDelay time.Duration UnhaltableSleep bool // contains filtered or unexported fields }
func (*TimedService) Halts ¶
func (d *TimedService) Halts() int
func (*TimedService) Init ¶
func (d *TimedService) Init() *TimedService
func (*TimedService) Starts ¶
func (d *TimedService) Starts() int
type UnhaltableService ¶
UnhaltableService is a defective service implementation for testing purposes.
It deliberately ignores service.Context.Done() and service.Context.ShouldHalt().
To stop it properly and ensure you are not leaking resources, use the Kill() function.
func (*UnhaltableService) Init ¶
func (u *UnhaltableService) Init() *UnhaltableService
func (*UnhaltableService) Kill ¶
func (u *UnhaltableService) Kill()