Documentation ¶
Index ¶
- func WithConduitFactory(factory network.ConduitFactory) func(*Network)
- type Buffer
- type Hub
- func (h *Hub) AddNetwork(net *Network)
- func (h *Hub) DeliverAll()
- func (h *Hub) DeliverAllEventually(t *testing.T, condition func() bool)
- func (h *Hub) DeliverAllEventuallyUntil(t *testing.T, condition func() bool, waitFor time.Duration, tick time.Duration)
- func (h *Hub) GetNetwork(nodeID flow.Identifier) (*Network, bool)
- type Network
- func (n *Network) DeliverAll(syncOnProcess bool)
- func (n *Network) DeliverAllExcept(syncOnProcess bool, shouldDrop func(*PendingMessage) bool)
- func (n *Network) DeliverSome(syncOnProcess bool, shouldDeliver func(*PendingMessage) bool)
- func (n *Network) GetID() flow.Identifier
- func (n *Network) MulticastOnChannel(channel channels.Channel, event interface{}, num uint, ...) error
- func (n *Network) PublishOnChannel(channel channels.Channel, event interface{}, targetIDs ...flow.Identifier) error
- func (n *Network) Register(channel channels.Channel, engine network.MessageProcessor) (network.Conduit, error)
- func (n *Network) ReportMisbehaviorOnChannel(_ channels.Channel, _ network.MisbehaviorReport)
- func (n *Network) StartConDev(updateInterval time.Duration, recursive bool)
- func (n *Network) StopConDev()
- func (n *Network) UnRegisterChannel(channel channels.Channel) error
- func (n *Network) UnicastOnChannel(channel channels.Channel, event interface{}, targetID flow.Identifier) error
- type PendingMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithConduitFactory ¶ added in v0.26.0
func WithConduitFactory(factory network.ConduitFactory) func(*Network)
Types ¶
type Buffer ¶
Buffer buffers all the pending messages to be sent over the mock network from one node to a list of nodes
func (*Buffer) Deliver ¶
func (b *Buffer) Deliver(sendOne func(*PendingMessage) bool)
Deliver delivers all pending messages currently in the buffer using the provided sendOne method. If sendOne returns false, the message was not sent and will remain in the buffer.
func (*Buffer) DeliverRecursive ¶
func (b *Buffer) DeliverRecursive(sendOne func(*PendingMessage))
DeliverRecursive recursively delivers all pending messages using the provided sendOne method until the buffer is empty. If sendOne does not deliver the message, it is permanently dropped.
func (*Buffer) Save ¶
func (b *Buffer) Save(m *PendingMessage)
Save stores a pending message to the buffer
type Hub ¶
Hub is a test helper that mocks a network overlay. It maintains a set of network instances and enables them to directly exchange message over the memory.
func NewNetworkHub ¶
func NewNetworkHub() *Hub
NewNetworkHub creates and returns a new Hub instance.
func (*Hub) AddNetwork ¶
AddNetwork stores the reference of the Network in the Hub, in order for networks to find other networks to send events directly.
func (*Hub) DeliverAll ¶
func (h *Hub) DeliverAll()
DeliverAll delivers all the buffered messages in the Network instances attached to the Hub to their destination. Note that the delivery of messages is done in asynchronous mode, i.e., sender and receiver are synchronized over delivery and not execution of the message.
func (*Hub) DeliverAllEventually ¶
DeliverAllEventually attempts on delivery of all the buffered messages in the Network instances attached to this instance of Hub. Once the delivery is done, it evaluates and returns the condition function. It fails if delivery of all buffered messages in the Network instances attached to this Hub is not getting done within 10 seconds. Note that the delivery of messages is done in asynchronous mode, i.e., sender and receiver are synchronized over delivery and not execution of the message.
func (*Hub) DeliverAllEventuallyUntil ¶
func (h *Hub) DeliverAllEventuallyUntil(t *testing.T, condition func() bool, waitFor time.Duration, tick time.Duration)
DeliverAllEventuallyUntil attempts attempts on delivery of all the buffered messages in the Network instances attached to this instance of Hub. Once the delivery is done, it evaluates and returns the condition function. It fails if delivery of all buffered messages in the Network instances attached to this Hub is not getting done within `waitFor` time interval. It checks the status of message deliveries at every `tick` time interval. Note that the delivery of messages is done in asynchronous mode, i.e., sender and receiver are synchronized over delivery and not execution of the message.
func (*Hub) GetNetwork ¶
func (h *Hub) GetNetwork(nodeID flow.Identifier) (*Network, bool)
GetNetwork returns the Network instance attached to the node ID.
type Network ¶
type Network struct { mocknetwork.Network sync.Mutex // contains filtered or unexported fields }
Network is a mocked Network layer made for testing engine's behavior. It represents the Network layer of a single node. A node can attach several engines of itself to the Network, and hence enabling them send and receive message. When an engine is attached on a Network instance, the mocked Network delivers all engine's events to others using an in-memory delivery mechanism.
func NewNetwork ¶
NewNetwork create a mocked Network. The committee has the identity of the node already, so only `committee` is needed in order for a mock hub to find each other.
func (*Network) DeliverAll ¶
DeliverAll sends all pending messages to the receivers. The receivers might be triggered to forward messages to its peers, so this function will block until all receivers have done their forwarding, and there is no more message in the Network to deliver.
func (*Network) DeliverAllExcept ¶
func (n *Network) DeliverAllExcept(syncOnProcess bool, shouldDrop func(*PendingMessage) bool)
DeliverAllExcept flushes all pending messages in the buffer except those that satisfy the shouldDrop predicate function. All messages that satisfy the shouldDrop predicate are permanently dropped. The message receivers might be triggered to forward some messages to their peers, so this function will block until all receivers have done their forwarding, and there is no more message in the Network to deliver.
If syncOnProcess is true, the sender and receiver are synchronized on processing the message. Otherwise they sync on delivery of the message.
func (*Network) DeliverSome ¶
func (n *Network) DeliverSome(syncOnProcess bool, shouldDeliver func(*PendingMessage) bool)
DeliverSome delivers all messages in the buffer that satisfy the shouldDeliver predicate. Any messages that are not delivered remain in the buffer.
If syncOnProcess is true, the sender and receiver are synchronized on processing the message. Otherwise they sync on delivery of the message.
func (*Network) GetID ¶
func (n *Network) GetID() flow.Identifier
GetID returns the identity of the attached node.
func (*Network) MulticastOnChannel ¶ added in v0.25.0
func (n *Network) MulticastOnChannel(channel channels.Channel, event interface{}, num uint, targetIDs ...flow.Identifier) error
multicast is called when an engine attached to the channel is sending an event to a number of randomly chosen Engines attached to the same channel on other nodes. The targeted nodes are selected based on the selector. In this test helper implementation, multicast uses submit method under the hood.
func (*Network) PublishOnChannel ¶ added in v0.25.0
func (n *Network) PublishOnChannel(channel channels.Channel, event interface{}, targetIDs ...flow.Identifier) error
publish is called when the attached Engine is sending an event to a group of Engines attached to the same channel on other nodes based on selector. In this test helper implementation, publish uses submit method under the hood.
func (*Network) Register ¶
func (n *Network) Register(channel channels.Channel, engine network.MessageProcessor) (network.Conduit, error)
Register registers an Engine of the attached node to the channel via a Conduit, and returns the Conduit instance.
func (*Network) ReportMisbehaviorOnChannel ¶ added in v0.31.0
func (n *Network) ReportMisbehaviorOnChannel(_ channels.Channel, _ network.MisbehaviorReport)
func (*Network) StartConDev ¶
StartConDev starts the continuous delivery mode of the Network. In this mode, the Network continuously checks the nodes' buffer every `updateInterval` milliseconds, and delivers all the pending messages. `recursive` determines whether the delivery is in recursive mode or not
func (*Network) StopConDev ¶
func (n *Network) StopConDev()
StopConDev stops the continuous deliver mode of the Network.
func (*Network) UnRegisterChannel ¶ added in v0.25.0
func (*Network) UnicastOnChannel ¶ added in v0.25.0
func (n *Network) UnicastOnChannel(channel channels.Channel, event interface{}, targetID flow.Identifier) error
unicast is called when the attached Engine to the channel is sending an event to a single target Engine attached to the same channel on another node.
type PendingMessage ¶
type PendingMessage struct { // The sender node id From flow.Identifier Channel channels.Channel Event interface{} // The id of the receiver nodes TargetIDs []flow.Identifier }
PendingMessage is a pending message to be sent