testing

package
v2.0.7+incompatible Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: GPL-3.0, LGPL-3.0, LGPL-3.0-or-later Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(msg interface{}) interface{}

Types

type Disconnect

type Disconnect struct {
	Peer  discover.NodeID // discconnected peer
	Error error           // disconnect reason
}

Disconnect represents a disconnect event, used and checked by TestDisconnected

type Exchange

type Exchange struct {
	Label    string
	Triggers []Trigger
	Expects  []Expect
	Timeout  time.Duration
}

Exchange is the basic units of protocol tests the triggers and expects in the arrays are run immediately and asynchronously thus one cannot have multiple expects for the SAME peer with DIFFERENT message types because it's unpredictable which expect will receive which message (with expect #1 and #2, messages might be sent #2 and #1, and both expects will complain about wrong message code) an exchange is defined on a session

type Expect

type Expect struct {
	Msg     interface{}     // type of message to expect
	Code    uint64          // code of message is now given
	Peer    discover.NodeID // the peer that expects the message
	Timeout time.Duration   // timeout duration for receiving
}

Expect is part of an exchange, outgoing message from the pivot node received by a peer

type ProtocolSession

type ProtocolSession struct {
	Server *p2p.Server
	IDs    []discover.NodeID
	// contains filtered or unexported fields
}

ProtocolSession is a quasi simulation of a pivot node running a service and a number of dummy peers that can send (trigger) or receive (expect) messages

func (*ProtocolSession) TestDisconnected

func (s *ProtocolSession) TestDisconnected(disconnects ...*Disconnect) error

TestDisconnected tests the disconnections given as arguments the disconnect structs describe what disconnect error is expected on which peer

func (*ProtocolSession) TestExchanges

func (s *ProtocolSession) TestExchanges(exchanges ...Exchange) error

TestExchanges tests a series of exchanges against the session

type ProtocolTester

type ProtocolTester struct {
	*ProtocolSession
	// contains filtered or unexported fields
}

ProtocolTester is the tester environment used for unit testing protocol message exchanges. It uses p2p/simulations framework

func NewProtocolTester

func NewProtocolTester(t *testing.T, id discover.NodeID, n int, run func(*p2p.Peer, p2p.MsgReadWriter) error) *ProtocolTester

NewProtocolTester constructs a new ProtocolTester it takes as argument the pivot node id, the number of dummy peers and the protocol run function called on a peer connection by the p2p server

func (*ProtocolTester) Connect

func (t *ProtocolTester) Connect(selfID discover.NodeID, peers ...*adapters.NodeConfig)

Connect brings up the remote peer node and connects it using the p2p/simulations network connection with the in memory network adapter

func (*ProtocolTester) Stop

func (t *ProtocolTester) Stop() error

Stop stops the p2p server

type TestPeer

type TestPeer interface {
	ID() discover.NodeID
	Drop(error)
}

type TestPeerPool

type TestPeerPool struct {
	// contains filtered or unexported fields
}

TestPeerPool is an example peerPool to demonstrate registration of peer connections

func NewTestPeerPool

func NewTestPeerPool() *TestPeerPool

func (*TestPeerPool) Add

func (p *TestPeerPool) Add(peer TestPeer)

func (*TestPeerPool) Get

func (p *TestPeerPool) Get(id discover.NodeID) TestPeer

func (*TestPeerPool) Has

func (p *TestPeerPool) Has(id discover.NodeID) bool

func (*TestPeerPool) Remove

func (p *TestPeerPool) Remove(peer TestPeer)

type Trigger

type Trigger struct {
	Msg     interface{}     // type of message to be sent
	Code    uint64          // code of message is given
	Peer    discover.NodeID // the peer to send the message to
	Timeout time.Duration   // timeout duration for the sending
}

Trigger is part of the exchange, incoming message for the pivot node sent by a peer

type WrappedMsg

type WrappedMsg struct {
	Context []byte
	Size    uint32
	Payload []byte
}

Jump to

Keyboard shortcuts

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