Documentation
¶
Overview ¶
Package testlib is the library for creating and running unit tests.
The package defines a test driver (TestingServer) that can be invoked with the created unit tests.
Index ¶
- Variables
- func IsMessageAcrossPartition() sm.Condition
- func IsMessageFromPart(partLabel string) sm.Condition
- func IsMessageWithinPartition() sm.Condition
- func NewTestDriver(ctx *context.RootContext, testcase *TestCase) *testCaseDriver
- type Action
- type Context
- type FilterFunc
- type FilterSet
- type FilterSetOption
- type FilterSetStats
- type IfThenHandler
- type Partition
- type TestCase
- type TestingServer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotEnoughReplicas occurs when creating a partition with a total size greater than the existing number of replicas ErrNotEnoughReplicas = errors.New("not enough replicas") // ErrSizeLabelsMismatch occurs when the number of labels does not match the number of partitions ErrSizeLabelsMismatch = errors.New("not enough labels") )
Functions ¶
func IsMessageAcrossPartition ¶ added in v0.2.1
IsMessageAcrossPartition condition returns true when the event represents a message between replicas of different partitions.
func IsMessageFromPart ¶ added in v0.1.1
IsMessageFromPart condition returns true when message is from a replica that belongs to the specified part.
func IsMessageWithinPartition ¶ added in v0.2.1
IsMessageWithinPartition condition returns true when the event represents a message between two replicas of the same partition.
func NewTestDriver ¶ added in v0.1.1
func NewTestDriver(ctx *context.RootContext, testcase *TestCase) *testCaseDriver
Types ¶
type Action ¶
Action is used to specify the consequence in the `If().Then()` handler
func DeliverAllFromSet ¶ added in v0.2.0
func DeliverAllFromSet(s *sm.SetWrapper) Action
DeliverAll returns an action which inturn returns all the messages in the message set and removes the messages from the set.
func DeliverMessage ¶
func DeliverMessage() Action
DeliverMessage returns the message if the event is a message send event
func IncrCounter ¶ added in v0.2.0
func IncrCounter(c *sm.CountWrapper) Action
IncrCounter returns an action which increments the counter value
func OnceAction ¶ added in v0.1.1
func RecordMessageAs ¶
RecordMessageAs returns an action. If the event is a message send or receive, the message is recorded in context with the label as reference
func StoreInSet ¶ added in v0.2.0
func StoreInSet(s *sm.SetWrapper) Action
Store returns an action. If the event is a message send or receive, the action adds the message to the message set
type Context ¶
Context struct is passed to the calls of StateAction and Condition encapsulates all information needed by the StateAction and Condition to function
func NewContext ¶ added in v0.2.0
func NewContext(c *context.RootContext, testcase *TestCase) *Context
NewContext instantiates a Context from the RootContext
func NewContextFrom ¶ added in v0.2.0
NewContextFrom instantiates a context from the specified state machine context and testcase.
func (*Context) CreatePartition ¶ added in v0.1.1
CreatePartition creates a new partition with the specified sizes and labels
func (*Context) EndTestCase ¶
func (c *Context) EndTestCase()
Ends the testcase without failing. The assertion will determine the success of the testcase
func (*Context) NewMessage ¶
func (c *Context) NewMessage(cur *types.Message, data []byte, pMsg types.ParsedMessage) *types.Message
NewMessage crafts a new message with a new ID The current message contents are replaced with `data`
type FilterFunc ¶
FilterFunc type to define a conditional handler returns false in the second return value if the handler is not concerned about the event
func IsolateNode ¶ added in v0.2.3
func IsolateNode(replica types.ReplicaID) FilterFunc
IsolateNode is a filter that drops all messages from and to the specified replica.
func NewStateMachineHandler ¶
func NewStateMachineHandler(stateMachine *sm.StateMachine) FilterFunc
NewStateMachineHandler returns a HandlerFunc that encodes the execution logic of the StateMachine For every invocation of the handler, internal a state machine step is executed which may or may not transition. If the StateMachine transitions to FailureState, the handler aborts the test case
type FilterSet ¶
type FilterSet struct {
Filters []FilterFunc
DefaultFilter FilterFunc
// contains filtered or unexported fields
}
FilterSet implements Handler Executes handlers in the specified order until the event is handled If no handler handles the event then the default handler is called
func NewFilterSet ¶
func NewFilterSet(opts ...FilterSetOption) *FilterSet
NewFilterSet creates a new cascade handler with the specified state machine and options
func (*FilterSet) AddFilter ¶
func (c *FilterSet) AddFilter(h FilterFunc)
AddFilter adds a handler to the cascade
func (*FilterSet) Stats ¶ added in v0.2.7
func (c *FilterSet) Stats() *FilterSetStats
Stats returns the stats
type FilterSetOption ¶
type FilterSetOption func(*FilterSet)
FilterSetOption changes the parameters of the HandlerCascade
func WithDefault ¶
func WithDefault(d FilterFunc) FilterSetOption
WithDefault changes the HandlerCascade default handler
type FilterSetStats ¶ added in v0.2.7
type FilterSetStats struct {
// contains filtered or unexported fields
}
FilterSetStats keeps a count of the number of times a filter condition was satisfied for a given filter The filter index is the order in which the filter is specified.
func (*FilterSetStats) MarshalJSON ¶ added in v0.2.7
func (s *FilterSetStats) MarshalJSON() ([]byte, error)
func (*FilterSetStats) String ¶ added in v0.2.7
func (s *FilterSetStats) String() string
type IfThenHandler ¶
type IfThenHandler struct {
// contains filtered or unexported fields
}
IfThenHandler struct is used to wrap the attributes of the `If().Then()` handler
func If ¶
func If(cond sm.Condition) *IfThenHandler
If creates a IfThenHandler with the specified condition
func (*IfThenHandler) Then ¶
func (i *IfThenHandler) Then(action Action, rest ...Action) FilterFunc
Then returns a HandlerFunc which encodes the `If().Then()` semantics. Accepts actions as arguments
type Partition ¶ added in v0.2.1
type Partition struct {
// contains filtered or unexported fields
}
Partition represents a logical partition between the replicas Partition can be used in filters and conditions to decide message delivery
func NewRandomPartition ¶ added in v0.2.2
NewRandomPartition creates a partition where replicas are assigned to partitions randomly
func (*Partition) GetPartLabel ¶ added in v0.2.1
GetPartLabel returns the part label the replica belongs to (if there is one), the second return value is false otherwise
func (*Partition) InPart ¶ added in v0.2.1
InPart returns true when the replica belongs to the specified part
type TestCase ¶
type TestCase struct {
// Name name of the testcase
Name string
// Timeout maximum duration of the testcase execution
Timeout time.Duration
// Setup function called prior to initiation of the execution
Setup func(*Context) error
// Cascade instance of *HandlerCascade
Cascade *FilterSet
// StateMachine instance of *StateMachine to assert a property
StateMachine *sm.StateMachine
// Logger to log information
Logger *log.Logger
// contains filtered or unexported fields
}
TestCase represents a unit test case
func NewTestCase ¶
func NewTestCase(name string, timeout time.Duration, sm *sm.StateMachine, cascade *FilterSet) *TestCase
NewTestCase instantiates a TestCase based on the parameters specified The new testcase has three states by default. - Start state where the execution starts from - Fail state that can be used to fail the testcase - Success state that can be used to indicate a success of the testcase
func (*TestCase) Reset ¶ added in v0.2.7
func (t *TestCase) Reset()
Reset clears the stats of the filter set and allows running the testcase again
type TestingServer ¶
type TestingServer struct {
*types.BaseService
// contains filtered or unexported fields
}
TestingServer is used to run the scheduler tool for unit testing
func NewTestingServer ¶
func NewTestingServer(config *config.Config, messageParser types.MessageParser, testcases []*TestCase) (*TestingServer, error)
NewTestingServer instantiates TestingServer testcases are passed as arguments
func (*TestingServer) Done ¶
func (srv *TestingServer) Done() chan string
Done returns the channel which will be closed once all testcases are run
func (*TestingServer) Name ¶
func (srv *TestingServer) Name() string
Name implements DashboardRouter
func (*TestingServer) SetupRouter ¶
func (srv *TestingServer) SetupRouter(router *gin.RouterGroup)
SetupRouter for setting up the dashboard routes implements DashboardRouter
func (*TestingServer) Start ¶
func (srv *TestingServer) Start()
Start starts the TestingServer and implements Service
func (*TestingServer) Stop ¶
func (srv *TestingServer) Stop()
Stop stops the TestingServer and implements Service