mock

package
v0.0.0-...-d504ea7 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeCluster

func InitializeCluster(a *assert.Assertions, numNodes int) (cluster *Cluster, nodes []*Node)

InitializeCluster creates a cluster and sets a different time on each Node

func NewServerForTest

func NewServerForTest(
	address *kronospb.NodeAddr,
	clock *tm.ManualClock,
	oracle oracle.StateMachine,
	client server.Client,
	oracleTimeCapDelta time.Duration,
	oracleUptimeCapDelta time.Duration,
) *server.Server

NewServerForTest returns a Server which can be used in unit tests

Types

type Client

type Client struct {

	// Latency is the Latency added to each request served
	Latency time.Duration
	// contains filtered or unexported fields
}

Client is an in memory implementation of Client used in tests This is tested in server_test.go

func (*Client) Close

func (c *Client) Close() error

Close closes all open connections.

func (*Client) KronosTime

func (c *Client) KronosTime(
	ctx context.Context, server *kronospb.NodeAddr,
) (*kronospb.KronosTimeResponse, error)

KronosTime implements the Client interface.

func (*Client) KronosUptime

func (c *Client) KronosUptime(ctx context.Context, server *kronospb.NodeAddr) (*kronospb.KronosUptimeResponse, error)

func (*Client) OracleTime

func (c *Client) OracleTime(
	ctx context.Context, server *kronospb.NodeAddr,
) (*kronospb.OracleTimeResponse, error)

OracleTime implements the Client interface.

func (*Client) Status

func (c *Client) Status(
	ctx context.Context, server *kronospb.NodeAddr,
) (*kronospb.StatusResponse, error)

Status implements the Client interface.

type Cluster

type Cluster struct {
	Nodes        map[string]*Node
	StateMachine oracle.StateMachine
	Client       *Client
	// contains filtered or unexported fields
}

Cluster is an in memory Kronos cluster used in tests

func NewKronosCluster

func NewKronosCluster(numNodes int) *Cluster

NewKronosCluster returns a new test kronos cluster

func (*Cluster) IsClusterInSync

func (tc *Cluster) IsClusterInSync(ctx context.Context, nodes ...*Node) error

IsClusterInSync returns whether kronos time is in sync on all the Nodes of the cluster

func (*Cluster) Node

func (tc *Cluster) Node(idx int) *Node

Node returns the Node given the Node index

func (*Cluster) RestartNode

func (tc *Cluster) RestartNode(ctx context.Context, testNode *Node) *Node

RestartNode replaces the given Node with a new Node

func (*Cluster) Stop

func (tc *Cluster) Stop()

Stop stops the all the kronos servers

func (*Cluster) StopNode

func (tc *Cluster) StopNode(ctx context.Context, testNode *Node)

StopNode stops the given kronos Node

func (*Cluster) Tick

func (tc *Cluster) Tick(testNode *Node)

Tick executes a Tick on the given Node and returns after the Tick is processed

func (*Cluster) TickN

func (tc *Cluster) TickN(testNode *Node, n int)

TickN executes Tick n times.

type Node

type Node struct {
	Server *server.Server
	Clock  *tm.ManualClock
	// contains filtered or unexported fields
}

Node is used by Cluster in tests

Jump to

Keyboard shortcuts

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