Documentation ¶
Overview ¶
Package script aids in the testing of code that uses channels.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Perform ¶
Given a set of Events, Perform repeatedly iterates over the set and finds the subset of ready Events (that is, all of their predecessors have occurred). From that subset, it pseudo-randomly selects an Event to perform. If the Event is a send event, the send occurs and Perform recalculates the ready set. If the event is a receive event, Perform waits for a value from any of the channels that are contained in any of the events. That value is then matched against the ready events. The first event that matches is considered to have occurred and Perform recalculates the ready set.
Perform continues this until all Events have occurred.
Note that uncollected goroutines may still be reading from any of the channels read from after Perform returns.
For example, consider the problem of testing a function that reads values on one channel and echos them to two output channels. To test this we would create three events: a send event and two receive events. Each of the receive events must list the send event as a predecessor but there is no ordering between the receive events.
send := NewEvent("send", nil, Send{c, 1}) recv1 := NewEvent("recv 1", []*Event{send}, Recv{c, 1}) recv2 := NewEvent("recv 2", []*Event{send}, Recv{c, 1}) Perform(0, []*Event{send, recv1, recv2})
At first, only the send event would be in the ready set and thus Perform will send a value to the input channel. Now the two receive events are ready and Perform will match each of them against the values read from the output channels.
It would be invalid to list one of the receive events as a predecessor of the other. At each receive step, all the receive channels are considered, thus Perform may see a value from a channel that is not in the current ready set and fail.
Types ¶
type Closed ¶
type Closed struct {
Channel interface{}
}
A Closed action matches if the given channel is closed. The closing is treated as an event, not a state, thus Closed will only match once for a given channel.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
An Event is an element in a partially ordered set that either sends a value to a channel or expects a value from a channel.
type ReceivedUnexpected ¶
type ReceivedUnexpected struct { Value interface{} // contains filtered or unexported fields }
A ReceivedUnexpected error results if no active Events match a value received from a channel.
func (ReceivedUnexpected) String ¶
func (r ReceivedUnexpected) String() string
type Recv ¶
type Recv struct { Channel interface{} Expected interface{} }
A Recv action reads a value from a channel and uses reflect.DeepMatch to compare it with an expected value.
type RecvMatch ¶
type RecvMatch struct { Channel interface{} Match func(interface{}) bool }
A RecvMatch action reads a value from a channel and calls a function to determine if the value matches.
type Send ¶
type Send struct { Channel interface{} Value interface{} }
A Send action sends a value to a channel. The value must match the type of the channel exactly unless the channel if of type chan interface{}.
type SetupError ¶
type SetupError string
A SetupError results if there is a error with the configuration of a set of Events.
func (SetupError) String ¶
func (s SetupError) String() string