test

package
v0.26.17-access-fix-dy... Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: AGPL-3.0 Imports: 38 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.Node, []observable.Observable)

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

func GenerateIDsMiddlewaresNetworks

func GenerateIDsMiddlewaresNetworks(
	ctx context.Context,
	t *testing.T,
	n int,
	log zerolog.Logger,
	tops []network.Topology,
	opts ...func(*optsConfig),
) (flow.IdentityList, []network.Middleware, []network.Network, []observable.Observable)

func GenerateNetworks

func GenerateNetworks(
	ctx context.Context,
	t *testing.T,
	log zerolog.Logger,
	ids flow.IdentityList,
	mws []network.Middleware,
	tops []network.Topology,
	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 GenerateTopologies

func GenerateTopologies(t *testing.T, state protocol.State, identities flow.IdentityList, logger zerolog.Logger) []network.Topology

CreateTopologies is a test helper on receiving an identity list, creates a topology per identity and returns the slice of topologies.

func WithDHT added in v0.23.9

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

func WithIdentityOpts added in v0.23.9

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

func WithPeerManagerOpts added in v0.23.9

func WithPeerManagerOpts(peerManagerOpts ...p2p.Option) 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 EchoEngine

type EchoEngine struct {
	sync.RWMutex

	mockcomponent.Component
	// contains filtered or unexported fields
}

EchoEngine is a simple engine that is used for testing the correctness of driving the engines with libp2p, in addition to receiving and storing incoming messages it also echos them back

func NewEchoEngine

func NewEchoEngine(t *testing.T, net network.Network, cap int, channel network.Channel, echo bool, send ConduitSendWrapperFunc) *EchoEngine

func (*EchoEngine) Process

func (te *EchoEngine) Process(channel network.Channel, originID flow.Identifier, event interface{}) error

Process receives an originID and an event and casts them into the corresponding fields of the EchoEngine. It then flags the received channel on reception of an event. It also sends back an echo of the message to the origin ID

func (*EchoEngine) ProcessLocal

func (te *EchoEngine) ProcessLocal(event interface{}) error

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

func (*EchoEngine) Submit

func (te *EchoEngine) Submit(channel network.Channel, originID flow.Identifier, event interface{})

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

func (*EchoEngine) SubmitLocal

func (te *EchoEngine) SubmitLocal(event interface{})

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

type MeshEngine

type MeshEngine struct {
	sync.Mutex

	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 network.Channel) *MeshEngine

func (*MeshEngine) Process

func (e *MeshEngine) Process(channel network.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 network.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 added in v0.21.0

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

type TagWatchingConnManager added in v0.21.0

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

func NewTagWatchingConnManager added in v0.21.0

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

func (*TagWatchingConnManager) Protect added in v0.21.0

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

func (*TagWatchingConnManager) Subscribe added in v0.21.0

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

func (*TagWatchingConnManager) Unprotect added in v0.21.0

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

func (*TagWatchingConnManager) Unsubscribe added in v0.21.0

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

type UpdatableIDProvider added in v0.21.1

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,
	opts ...func(*optsConfig),
) (flow.IdentityList, []network.Middleware, []observable.Observable, []*UpdatableIDProvider)

GenerateIDsAndMiddlewares returns nodeIDs, 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.Node, opts ...func(*optsConfig)) ([]network.Middleware, []*UpdatableIDProvider)

GenerateMiddlewares creates and initializes middleware instances for all the identities

func NewUpdatableIDProvider added in v0.21.1

func NewUpdatableIDProvider(identities flow.IdentityList) *UpdatableIDProvider

func (*UpdatableIDProvider) ByNodeID added in v0.21.1

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

func (*UpdatableIDProvider) ByPeerID added in v0.21.1

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

func (*UpdatableIDProvider) Identifiers added in v0.21.1

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

func (*UpdatableIDProvider) Identities added in v0.21.1

func (*UpdatableIDProvider) SetIdentities added in v0.21.1

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