testing

package
v1.5.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 (self *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 (self *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 (self *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 (self *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 (self *TestPeerPool) Add(p TestPeer)

func (*TestPeerPool) Get

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

func (*TestPeerPool) Has

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

func (*TestPeerPool) Remove

func (self *TestPeerPool) Remove(p 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

Jump to

Keyboard shortcuts

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