stub

package
v0.23.7 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: AGPL-3.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Buffer buffers all the pending messages to be sent over the mock network from one node to a list of nodes

func NewBuffer

func NewBuffer() *Buffer

NewBuffer initialize the Buffer

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 Conduit

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

func (*Conduit) Close

func (c *Conduit) Close() error

func (*Conduit) Multicast

func (c *Conduit) Multicast(event interface{}, num uint, targetIDs ...flow.Identifier) error

func (*Conduit) Publish

func (c *Conduit) Publish(event interface{}, targetIDs ...flow.Identifier) error

func (*Conduit) Unicast

func (c *Conduit) Unicast(event interface{}, targetID flow.Identifier) error

type Hub

type Hub struct {
	Buffer *Buffer
	// contains filtered or unexported fields
}

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

func (h *Hub) AddNetwork(net *Network)

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

func (h *Hub) DeliverAllEventually(t *testing.T, condition func() bool)

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 {
	sync.Mutex

	mocknetwork.Network
	// 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

func NewNetwork(state protocol.State, me module.Local, hub *Hub) *Network

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

func (n *Network) DeliverAll(syncOnProcess bool)

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) Register

func (n *Network) Register(channel network.Channel, engine network.Engine) (network.Conduit, error)

Register registers an Engine of the attached node to the channel via a Conduit, and returns the Conduit instance.

func (*Network) StartConDev

func (n *Network) StartConDev(updateInterval time.Duration, recursive bool)

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) Unregister

func (n *Network) Unregister(channel network.Channel) error

type PendingMessage

type PendingMessage struct {
	// The sender node id
	From    flow.Identifier
	Channel network.Channel
	Event   interface{}
	// The id of the receiver nodes
	TargetIDs []flow.Identifier
}

PendingMessage is a pending message to be sent

Jump to

Keyboard shortcuts

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