Documentation ¶
Overview ¶
Package testkit extends the in-process transport adapter with Tampering capabilities, intended to be used by system-wide acceptance tests
Index ¶
- func ABenchmarkConsensusMessage(header *gossipmessages.Header) bool
- func AConsensusMessage(header *gossipmessages.Header) bool
- func ATransactionRelayMessage(header *gossipmessages.Header) bool
- type HeaderPredicate
- type LatchingTamper
- type MessagePredicate
- func BenchmarkConsensusMessage(messageType consensus.BenchmarkConsensusMessageType) MessagePredicate
- func BlockSyncMessage(messageType gossipmessages.BlockSyncMessageType) MessagePredicate
- func HasHeader(headerPredicate HeaderPredicate) MessagePredicate
- func Not(predicate MessagePredicate) MessagePredicate
- func TransactionRelayMessage(messageType gossipmessages.TransactionsRelayMessageType) MessagePredicate
- type MockTransportListener
- func (l *MockTransportListener) BlockReceive()
- func (l *MockTransportListener) ExpectNotReceive()
- func (l *MockTransportListener) ExpectReceive(payloads [][]byte)
- func (l *MockTransportListener) ExpectTracingContextToPropagate(t *testing.T, originalTracingContext *trace.Context) *mock.MockFunction
- func (l *MockTransportListener) OnTransportMessageReceived(ctx context.Context, payloads [][]byte)
- func (l *MockTransportListener) WhenOnTransportMessageReceived(arg interface{}) *mock.MockFunction
- type OngoingTamper
- type Tamperer
- type TamperingTransport
- func (t *TamperingTransport) Corrupt(predicate MessagePredicate, ctrlRand *rand.ControlledRand) OngoingTamper
- func (t *TamperingTransport) Delay(duration func() time.Duration, predicate MessagePredicate) OngoingTamper
- func (t *TamperingTransport) Duplicate(predicate MessagePredicate) OngoingTamper
- func (t *TamperingTransport) Fail(predicate MessagePredicate) OngoingTamper
- func (t *TamperingTransport) LatchOn(predicate MessagePredicate) LatchingTamper
- func (t *TamperingTransport) Pause(predicate MessagePredicate) OngoingTamper
- func (t *TamperingTransport) RegisterListener(listener adapter.TransportListener, listenerNodeAddress primitives.NodeAddress)
- func (t *TamperingTransport) Send(ctx context.Context, data *adapter.TransportData) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ABenchmarkConsensusMessage ¶
func ABenchmarkConsensusMessage(header *gossipmessages.Header) bool
func AConsensusMessage ¶
func AConsensusMessage(header *gossipmessages.Header) bool
func ATransactionRelayMessage ¶
func ATransactionRelayMessage(header *gossipmessages.Header) bool
Types ¶
type HeaderPredicate ¶
type HeaderPredicate func(header *gossipmessages.Header) bool
type LatchingTamper ¶
type LatchingTamper interface { Wait() Remove() }
type MessagePredicate ¶
type MessagePredicate func(data *adapter.TransportData) bool
A predicate for matching messages with a certain property
Example (PayloadSize) ¶
aMessageWithPayloadOver := func(maxSizeInBytes int) MessagePredicate { return func(data *adapter.TransportData) bool { size := 0 for _, payload := range data.Payloads { size += len(payload) } return size < maxSizeInBytes } } pred := aMessageWithPayloadOver(100) printMessage := func(payloads [][]byte) { if pred(&adapter.TransportData{Payloads: payloads}) { fmt.Println("got message smaller than 100 bytes") } else { fmt.Println("got message larger than 100 bytes") } } printMessage([][]byte{make([]byte, 10)}) printMessage([][]byte{make([]byte, 1000)})
Output: got message smaller than 100 bytes got message larger than 100 bytes
Example (Sender) ¶
aMessageFrom := func(sender string) MessagePredicate { return func(data *adapter.TransportData) bool { return string(data.SenderNodeAddress) == sender } } pred := aMessageFrom("sender1") printSender := func(sender string) { if pred(&adapter.TransportData{SenderNodeAddress: primitives.NodeAddress(sender)}) { fmt.Printf("got message from %s\n", sender) } else { fmt.Println("got message from other sender") } } printSender("sender1") printSender("sender3")
Output: got message from sender1 got message from other sender
func BenchmarkConsensusMessage ¶
func BenchmarkConsensusMessage(messageType consensus.BenchmarkConsensusMessageType) MessagePredicate
func BlockSyncMessage ¶
func BlockSyncMessage(messageType gossipmessages.BlockSyncMessageType) MessagePredicate
func HasHeader ¶
func HasHeader(headerPredicate HeaderPredicate) MessagePredicate
func Not ¶
func Not(predicate MessagePredicate) MessagePredicate
func TransactionRelayMessage ¶
func TransactionRelayMessage(messageType gossipmessages.TransactionsRelayMessageType) MessagePredicate
func (MessagePredicate) And ¶
func (this MessagePredicate) And(other MessagePredicate) MessagePredicate
type MockTransportListener ¶
type MockTransportListener struct {
mock.Mock
}
func ListenTo ¶
func ListenTo(transport adapter.Transport, nodeAddress primitives.NodeAddress) *MockTransportListener
func (*MockTransportListener) BlockReceive ¶
func (l *MockTransportListener) BlockReceive()
func (*MockTransportListener) ExpectNotReceive ¶
func (l *MockTransportListener) ExpectNotReceive()
func (*MockTransportListener) ExpectReceive ¶
func (l *MockTransportListener) ExpectReceive(payloads [][]byte)
func (*MockTransportListener) ExpectTracingContextToPropagate ¶
func (l *MockTransportListener) ExpectTracingContextToPropagate(t *testing.T, originalTracingContext *trace.Context) *mock.MockFunction
func (*MockTransportListener) OnTransportMessageReceived ¶
func (l *MockTransportListener) OnTransportMessageReceived(ctx context.Context, payloads [][]byte)
func (*MockTransportListener) WhenOnTransportMessageReceived ¶
func (l *MockTransportListener) WhenOnTransportMessageReceived(arg interface{}) *mock.MockFunction
type OngoingTamper ¶
type Tamperer ¶
type Tamperer interface { // Creates an ongoing tamper which fails messages matching the given predicate, returning an error object to the sender. // This is useful to emulate network errors, for instance Fail(predicate MessagePredicate) OngoingTamper // Creates an ongoing tamper which delays messages matching the given predicate. The messages will be sent when // calling OngoingTamper.StopTampering(). This is useful for emulating network congestion or messages arriving in an order // different than expected Pause(predicate MessagePredicate) OngoingTamper // Creates an ongoing tamper which latches the latching goroutine (typically a test) until at least one message // matching the given predicate is sent. The latch is created as inactive, and will only block the caller after // calling LatchingTamper.Wait(). This is useful to force a test goroutine to block until a certain message has // been sent LatchOn(predicate MessagePredicate) LatchingTamper // Creates an ongoing tamper which duplicates messages matching the given predicate Duplicate(predicate MessagePredicate) OngoingTamper // Creates an ongoing tamper which corrupts messages matching the given predicate Corrupt(predicate MessagePredicate, rand *rand.ControlledRand) OngoingTamper // Creates an ongoing tamper which delays (reshuffles) messages matching the given predicate for the specified duration Delay(duration func() time.Duration, predicate MessagePredicate) OngoingTamper }
The TamperingTransport is an in-memory implementation of the Gossip Transport adapter, that adds the ability to tamper with the messages or to synchronize the test's goroutine with the SUT's goroutines
type TamperingTransport ¶
type TamperingTransport struct {
// contains filtered or unexported fields
}
func NewTamperingTransport ¶
func NewTamperingTransport(logger log.Logger, nested adapter.Transport) *TamperingTransport
func (*TamperingTransport) Corrupt ¶
func (t *TamperingTransport) Corrupt(predicate MessagePredicate, ctrlRand *rand.ControlledRand) OngoingTamper
func (*TamperingTransport) Delay ¶
func (t *TamperingTransport) Delay(duration func() time.Duration, predicate MessagePredicate) OngoingTamper
func (*TamperingTransport) Duplicate ¶
func (t *TamperingTransport) Duplicate(predicate MessagePredicate) OngoingTamper
func (*TamperingTransport) Fail ¶
func (t *TamperingTransport) Fail(predicate MessagePredicate) OngoingTamper
func (*TamperingTransport) LatchOn ¶
func (t *TamperingTransport) LatchOn(predicate MessagePredicate) LatchingTamper
func (*TamperingTransport) Pause ¶
func (t *TamperingTransport) Pause(predicate MessagePredicate) OngoingTamper
func (*TamperingTransport) RegisterListener ¶
func (t *TamperingTransport) RegisterListener(listener adapter.TransportListener, listenerNodeAddress primitives.NodeAddress)
func (*TamperingTransport) Send ¶
func (t *TamperingTransport) Send(ctx context.Context, data *adapter.TransportData) error
Click to show internal directories.
Click to hide internal directories.