testlib

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 14 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotEnoughReplicas  = errors.New("not enough replicas")
	ErrSizeLabelsMismatch = errors.New("sizes and labels are not of the same length")
)

Functions

func IsMessageAcrossPartition added in v0.2.1

func IsMessageAcrossPartition() sm.Condition

func IsMessageFromPart added in v0.1.1

func IsMessageFromPart(partLabel string) sm.Condition

func IsMessageWithinPartition added in v0.2.1

func IsMessageWithinPartition() sm.Condition

func NewReportStore

func NewReportStore() *reportStore

Types

type Action

type Action func(*types.Event, *Context) []*types.Message

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 DropMessage

func DropMessage() Action

DropMessage returns an empty list of messages

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 OnceAction(name string, action Action) Action

func RecordMessageAs

func RecordMessageAs(label string) Action

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

type Context struct {
	*sm.Context
	// contains filtered or unexported fields
}

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

func NewContextFrom(sm *sm.Context, testcase *TestCase) *Context

func (*Context) Abort

func (c *Context) Abort()

Abort stops the execution of the testcase

func (*Context) CreatePartition added in v0.1.1

func (c *Context) CreatePartition(sizes []int, labels []string)

func (*Context) EndTestCase

func (c *Context) EndTestCase()

Ends the testcase without failing. The assertion will determine the success of the testcase

func (*Context) Log

func (c *Context) Log(keyvals map[string]string)

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

type FilterFunc func(*types.Event, *Context) ([]*types.Message, bool)

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

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
}

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

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 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
}

func NewRandomPartition added in v0.2.2

func NewRandomPartition(sizes []int, labels []string) (*Partition, error)

func (*Partition) GetPartLabel added in v0.2.1

func (p *Partition) GetPartLabel(replica types.ReplicaID) (string, bool)

func (*Partition) InPart added in v0.2.1

func (p *Partition) InPart(replica types.ReplicaID, partLabel string) bool

func (*Partition) Setup added in v0.2.1

func (p *Partition) Setup(ctx *Context) error

func (*Partition) String added in v0.2.1

func (p *Partition) String() string

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) Abort

func (t *TestCase) Abort()

Abort the testcase

func (*TestCase) End

func (t *TestCase) End()

End the testcase

func (*TestCase) SetupFunc

func (t *TestCase) SetupFunc(setupFunc func(*Context) error)

SetupFunc can be used to set the setup function

func (*TestCase) Step added in v0.2.0

func (t *TestCase) Step(e *types.Event, c *Context) ([]*types.Message, bool)

Step is called to execute a step of the testcase with a new event

type TestCaseDriver added in v0.1.1

type TestCaseDriver struct {
	TestCase *TestCase
	// contains filtered or unexported fields
}

func NewTestDriver added in v0.1.1

func NewTestDriver(ctx *context.RootContext, testcase *TestCase) *TestCaseDriver

func (*TestCaseDriver) Step added in v0.1.1

func (d *TestCaseDriver) Step(e *types.Event) []*types.Message

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

Jump to

Keyboard shortcuts

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