testutils

package
v0.29.6-with-pr-3835 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: AGPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateIDs

func GenerateIDs(t *testing.T, logger zerolog.Logger, n int, opts ...func(*optsConfig)) (flow.IdentityList,
	[]p2p.LibP2PNode,
	[]observable.Observable)

GenerateIDs is a test helper that generate flow identities with a valid port and libp2p nodes.

func GenerateIDsMiddlewaresNetworks

func GenerateIDsMiddlewaresNetworks(t *testing.T,
	n int,
	log zerolog.Logger,
	codec network.Codec,
	consumer slashing.ViolationsConsumer,
	opts ...func(*optsConfig)) (flow.IdentityList, []p2p.LibP2PNode, []network.Middleware, []network.Network, []observable.Observable)

func GenerateNetworks

func GenerateNetworks(t *testing.T,
	log zerolog.Logger,
	ids flow.IdentityList,
	mws []network.Middleware,
	sms []network.SubscriptionManager) []network.Network

GenerateNetworks generates the network for the given middlewares

func GenerateSubscriptionManagers

func GenerateSubscriptionManagers(t *testing.T, mws []network.Middleware) []network.SubscriptionManager

GenerateSubscriptionManagers creates and returns a ChannelSubscriptionManager for each middleware object.

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 NewConnectionGater

func NewConnectionGater(allowListFilter p2p.PeerFilter) connmgr.ConnectionGater

NewConnectionGater creates a new connection gater for testing with given allow listing filter.

func NewResourceManager

func NewResourceManager(t *testing.T) p2pNetwork.ResourceManager

NewResourceManager creates a new resource manager for testing with no limits.

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 StartNodes

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

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.Network, duration time.Duration)

StartNodesAndNetworks starts the provided networks and libp2p nodes, returning the irrecoverable error channel

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.

func WithDHT

func WithDHT(prefix string, dhtOpts ...dht.Option) func(*optsConfig)

func WithIdentityOpts

func WithIdentityOpts(idOpts ...func(*flow.Identity)) func(*optsConfig)

func WithNetworkMetrics

func WithNetworkMetrics(m module.NetworkMetrics) func(*optsConfig)

func WithPeerUpdateInterval

func WithPeerUpdateInterval(interval time.Duration) func(*optsConfig)

func WithUnicastRateLimiters

func WithUnicastRateLimiters(limiters *ratelimit.RateLimiters) func(*optsConfig)

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 GenerateEngines

func GenerateEngines(t *testing.T, nets []network.Network) []*MeshEngine

GenerateEngines generates MeshEngines for the given networks

func NewMeshEngine

func NewMeshEngine(t *testing.T, net network.Network, 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 TagWatchingConnManager

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

func NewTagWatchingConnManager

func NewTagWatchingConnManager(log zerolog.Logger, idProvider module.IdentityProvider, metrics module.NetworkMetrics) *TagWatchingConnManager

func (*TagWatchingConnManager) Protect

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

func (*TagWatchingConnManager) Subscribe

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

func (*TagWatchingConnManager) Unprotect

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

func (*TagWatchingConnManager) Unsubscribe

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

type UpdatableIDProvider

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

UpdatableIDProvider implements an IdentityProvider which can be manually updated by setting the IdentityList to a new value. It also implements an IdentifierProvider which provides the identifiers of the IdentityList. This is mainly used to simulate epoch transitions in tests.

func GenerateIDsAndMiddlewares

func GenerateIDsAndMiddlewares(t *testing.T,
	n int,
	logger zerolog.Logger,
	codec network.Codec,
	consumer slashing.ViolationsConsumer,
	opts ...func(*optsConfig)) (flow.IdentityList, []p2p.LibP2PNode, []network.Middleware, []observable.Observable, []*UpdatableIDProvider)

GenerateIDsAndMiddlewares returns nodeIDs, libp2pNodes, middlewares, and observables which can be subscirbed to in order to witness protect events from pubsub

func GenerateMiddlewares

func GenerateMiddlewares(t *testing.T,
	logger zerolog.Logger,
	identities flow.IdentityList,
	libP2PNodes []p2p.LibP2PNode,
	codec network.Codec,
	consumer slashing.ViolationsConsumer,
	opts ...func(*optsConfig)) ([]network.Middleware, []*UpdatableIDProvider)

GenerateMiddlewares creates and initializes middleware instances for all the identities

func NewUpdatableIDProvider

func NewUpdatableIDProvider(identities flow.IdentityList) *UpdatableIDProvider

func (*UpdatableIDProvider) ByNodeID

func (p *UpdatableIDProvider) ByNodeID(flowID flow.Identifier) (*flow.Identity, bool)

func (*UpdatableIDProvider) ByPeerID

func (p *UpdatableIDProvider) ByPeerID(peerID peer.ID) (*flow.Identity, bool)

func (*UpdatableIDProvider) Identifiers

func (p *UpdatableIDProvider) Identifiers() flow.IdentifierList

func (*UpdatableIDProvider) Identities

func (*UpdatableIDProvider) SetIdentities

func (p *UpdatableIDProvider) SetIdentities(identities flow.IdentityList)

SetIdentities updates the IdentityList returned by this provider.

Jump to

Keyboard shortcuts

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