testutils

package
v0.33.20 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRateLimitedPeerFilter added in v0.30.0

func IsRateLimitedPeerFilter(rateLimiter p2p.RateLimiter) p2p.PeerFilter

IsRateLimitedPeerFilter returns a p2p.PeerFilter that will return an error if the peer is rate limited.

func LibP2PNodeForNetworkFixture added in v0.32.0

func LibP2PNodeForNetworkFixture(t *testing.T, sporkId flow.Identifier, n int, opts ...p2ptest.NodeFixtureParameterOption) (flow.IdentityList, []p2p.LibP2PNode)

LibP2PNodeForNetworkFixture is a test helper that generate flow identities with a valid port and libp2p nodes. Note that the LibP2PNode created by this fixture is meant to used with a network component. If you want to create a standalone LibP2PNode without network component, please use p2ptest.NodeFixture. Args:

t: testing.T- the test object
sporkId: flow.Identifier - the spork id to use for the nodes
n: int - number of nodes to create

opts: []p2ptest.NodeFixtureParameterOption - options to configure the nodes Returns:

flow.IdentityList - list of identities created for the nodes, one for each node.

[]p2p.LibP2PNode - list of libp2p nodes created. TODO: several test cases only need a single node, consider encapsulating this function in a single node fixture.

func MisbehaviorReportFixture added in v0.31.0

func MisbehaviorReportFixture(t *testing.T) network.MisbehaviorReport

MisbehaviorReportFixture generates a random misbehavior report. Args:

  • t: the test object.

This is used in tests to generate random misbehavior reports. It fails the test if it cannot generate a valid report.

func MisbehaviorReportsFixture added in v0.31.0

func MisbehaviorReportsFixture(t *testing.T, count int) []network.MisbehaviorReport

MisbehaviorReportsFixture generates a slice of random misbehavior reports. Args:

  • t: the test object.

It fails the test if it cannot generate a valid report. This is used in tests to generate random misbehavior reports.

func MisbehaviorTypeFixture added in v0.31.0

func MisbehaviorTypeFixture(_ *testing.T) network.Misbehavior

MisbehaviorTypeFixture generates a random misbehavior type. Args:

  • t: the test object (used to emphasize that this is a test helper).

func NetworkConfigFixture added in v0.31.0

func NetworkConfigFixture(
	t *testing.T,
	myId flow.Identity,
	idProvider module.IdentityProvider,
	sporkId flow.Identifier,
	libp2pNode p2p.LibP2PNode,
	opts ...underlay.NetworkConfigOption) *underlay.NetworkConfig

func NetworkPayloadFixture

func NetworkPayloadFixture(t *testing.T, size uint) []byte

NetworkPayloadFixture creates a blob of random bytes with the given size (in bytes) and returns it. The primary goal of utilizing this helper function is to apply stress tests on the network layer by sending large messages to transmit.

func NetworksFixture added in v0.31.0

func NetworksFixture(t *testing.T,
	sporkId flow.Identifier,
	ids flow.IdentityList,
	libp2pNodes []p2p.LibP2PNode,
	configOpts ...func(*underlay.NetworkConfig)) ([]*underlay.Network, []*unittest.UpdatableIDProvider)

NetworksFixture generates the network for the given libp2p nodes.

func NewRateLimiterConsumer added in v0.30.0

func NewRateLimiterConsumer(callback func(pid peer.ID, role, msgType, topic, reason string)) p2p.RateLimiterConsumer

NewRateLimiterConsumer returns a p2p.RateLimiterConsumer fixture that will invoke the callback provided.

func OptionalSleep

func OptionalSleep(send ConduitSendWrapperFunc)

OptionalSleep introduces a sleep to allow nodes to heartbeat and discover each other (only needed when using PubSub)

func StartNetworks added in v0.31.0

func StartNetworks(ctx irrecoverable.SignalerContext, t *testing.T, nets []network.EngineRegistry)

StartNetworks starts the provided networks using the provided irrecoverable context Arguments: - ctx: the irrecoverable context to use for starting the networks. - t: the test object. - nets: the networks to start. - duration: the timeout to use for waiting for the networks to start.

This function fails the test if the networks do not start within the given timeout.

func StartNodes

func StartNodes(ctx irrecoverable.SignalerContext, t *testing.T, nodes []p2p.LibP2PNode)

StartNodes starts the provided nodes and their peer managers using the provided irrecoverable context

func StartNodesAndNetworks

func StartNodesAndNetworks(ctx irrecoverable.SignalerContext, t *testing.T, nodes []p2p.LibP2PNode, nets []network.EngineRegistry)

StartNodesAndNetworks starts the provided networks and libp2p nodes, returning the irrecoverable error channel. Arguments: - ctx: the irrecoverable context to use for starting the nodes and networks. - t: the test object. - nodes: the libp2p nodes to start. - nets: the networks to start. - timeout: the timeout to use for waiting for the nodes and networks to start.

This function fails the test if the nodes or networks do not start within the given timeout.

func StopComponents

func StopComponents[R module.ReadyDoneAware](t *testing.T, rda []R, duration time.Duration)

StopComponents stops ReadyDoneAware instances in parallel and fails the test if they could not be stopped within the duration.

Types

type ConduitSendWrapperFunc

type ConduitSendWrapperFunc func(msg interface{}, conduit network.Conduit, targetIDs ...flow.Identifier) error

ConduitSendWrapperFunc is a wrapper around the set of methods offered by the Conduit (e.g., Publish). This data type is solely introduced at the test level. Its primary purpose is to make the same test reusable on different Conduit methods.

type ConduitWrapper

type ConduitWrapper struct{}

func (*ConduitWrapper) Multicast

func (c *ConduitWrapper) Multicast(msg interface{}, conduit network.Conduit, targetIDs ...flow.Identifier) error

Multicast defines a function that receives a message, conduit of an engine instance, and a set of target ID. It then sends the message to the target IDs using the Multicast method of conduit.

func (*ConduitWrapper) Publish

func (c *ConduitWrapper) Publish(msg interface{}, conduit network.Conduit, targetIDs ...flow.Identifier) error

Publish defines a function that receives a message, conduit of an engine instance, and a set target IDs. It then sends the message to the target IDs using the Publish method of conduit.

func (*ConduitWrapper) Unicast

func (c *ConduitWrapper) Unicast(msg interface{}, conduit network.Conduit, targetIDs ...flow.Identifier) error

Unicast defines a function that receives a message, conduit of an engine instance, and a set of target IDs. It then sends the message to the target IDs using individual Unicasts to each target in the underlying network.

type MeshEngine

type MeshEngine struct {
	sync.Mutex

	Con network.Conduit // used to directly communicate with the network

	Event    chan interface{}      // used to keep track of the events that the node receives
	Channel  chan channels.Channel // used to keep track of the channels that events are Received on
	Received chan struct{}         // used as an indicator on reception of messages for testing
	mockcomponent.Component
	// contains filtered or unexported fields
}

MeshEngine is a simple engine that is used for testing the correctness of driving the engines with libp2p, it simply receives and stores the incoming messages

func NewMeshEngine

func NewMeshEngine(t *testing.T, net network.EngineRegistry, cap int, channel channels.Channel) *MeshEngine

func (*MeshEngine) Process

func (e *MeshEngine) Process(channel channels.Channel, originID flow.Identifier, event interface{}) error

Process receives an originID and an Event and casts them into the corresponding fields of the MeshEngine. It then flags the Received Channel on reception of an Event.

func (*MeshEngine) ProcessLocal

func (e *MeshEngine) ProcessLocal(event interface{}) error

ProcessLocal is implemented for a valid type assertion to Engine any call to it fails the test

func (*MeshEngine) Submit

func (e *MeshEngine) Submit(channel channels.Channel, originID flow.Identifier, event interface{})

Submit is implemented for a valid type assertion to Engine any call to it fails the test

func (*MeshEngine) SubmitLocal

func (e *MeshEngine) SubmitLocal(event interface{})

SubmitLocal is implemented for a valid type assertion to Engine any call to it fails the test

type PeerTag

type PeerTag struct {
	Peer peer.ID
	Tag  string
}

type RateLimitConsumer added in v0.30.0

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

RateLimitConsumer p2p.RateLimiterConsumer fixture that invokes a callback when rate limit event is consumed.

func (*RateLimitConsumer) OnRateLimitedPeer added in v0.30.0

func (r *RateLimitConsumer) OnRateLimitedPeer(pid peer.ID, role, msgType, topic, reason string)

type TagWatchingConnManager

type TagWatchingConnManager struct {
	*connection.ConnManager
	// contains filtered or unexported fields
}

TagWatchingConnManager implements connection.ConnManager struct, and manages connections with tags. It also maintains a set of observers that it notifies when a tag is added or removed from a peer.

func NewTagWatchingConnManager

func NewTagWatchingConnManager(log zerolog.Logger, metrics module.LibP2PConnectionMetrics, config *netconf.ConnectionManager) (*TagWatchingConnManager, error)

NewTagWatchingConnManager creates a new TagWatchingConnManager with the given config. It returns an error if the config is invalid.

func (*TagWatchingConnManager) Protect

func (tw *TagWatchingConnManager) Protect(id peer.ID, tag string)

Protect adds a tag to a peer. It also notifies all observers that a tag has been added to a peer.

func (*TagWatchingConnManager) Subscribe

func (tw *TagWatchingConnManager) Subscribe(observer observable.Observer)

Subscribe allows an observer to subscribe to receive notifications when a tag is added or removed from a peer.

func (*TagWatchingConnManager) Unprotect

func (tw *TagWatchingConnManager) Unprotect(id peer.ID, tag string) bool

Unprotect removes a tag from a peer. It also notifies all observers that a tag has been removed from a peer.

func (*TagWatchingConnManager) Unsubscribe

func (tw *TagWatchingConnManager) Unsubscribe(observer observable.Observer)

Unsubscribe allows an observer to unsubscribe from receiving notifications.

Jump to

Keyboard shortcuts

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