Documentation
¶
Overview ¶
Package grpcproctest runs a grpcproc cluster inside one test binary. Nodes talk over in-memory gRPC connections (bufconn), so a multi-node scenario, including a partition or a node dying, needs no sockets and no registry.
Its nodes dial a peer again at once after a dial to it failed (Config.DialBackoff is negative), so the send right after Heal or Restart reaches the peer. Set DialBackoff with WithConfig to test the backoff.
Index ¶
- Variables
- type Cluster
- func (c *Cluster) Conn(name string) *grpc.ClientConn
- func (c *Cluster) CutNames(name string)
- func (c *Cluster) DialOptions() []grpc.DialOption
- func (c *Cluster) Heal(a, b string)
- func (c *Cluster) Kill(name string)
- func (c *Cluster) Names() *Names
- func (c *Cluster) Node(name string) *grpcproc.Node
- func (c *Cluster) Partition(a, b string)
- func (*Cluster) Resolver() grpcproc.Resolver
- func (c *Cluster) Restart(name string) *grpcproc.Node
- func (c *Cluster) RestoreNames(name string)
- func (c *Cluster) Stop(name string)
- type Names
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrNamesUnreachable = errors.New("grpcproctest: names out of reach")
ErrNamesUnreachable is what a node cut off from the names (Cluster.CutNames) gets from a claim or a Resolve.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster is a set of nodes and the (simulated) network between them.
func (*Cluster) Conn ¶
func (c *Cluster) Conn(name string) *grpc.ClientConn
Conn returns a client connection to the gRPC server of node name, for calling services registered with WithServices. It is not subject to Partition, and it follows the node across Restart.
func (*Cluster) CutNames ¶ added in v0.4.0
CutNames cuts name off from the global names, as from etcd for longer than its lease: its processes' claims are lost, which ends them with ReasonNameLost, or, made with KeepOnLoss, leaves them running, not held; their names are free for the other nodes; and its claims and Resolves fail with ErrNamesUnreachable until RestoreNames.
func (*Cluster) DialOptions ¶
func (c *Cluster) DialOptions() []grpc.DialOption
DialOptions reach the cluster's in-memory servers from outside any node: not subject to Partition, and following a node across Restart.
func (*Cluster) Kill ¶
Kill stops name abruptly, as a crash would: no Down{shutdown} reaches anyone; peers see their links break. They have by the time Kill returns, monitors fired and calls failed, so the next send to name fails, and after Restart reaches the new node (dials are not backed off; see the package doc).
func (*Cluster) Names ¶ added in v0.4.0
Names is the store of the cluster's global names: every node's Config.Names is a view of it, unless WithConfig sets another.
func (*Cluster) Partition ¶
Partition cuts the network between a and b in both directions: existing links break (monitors fire Down{noconnection}) and new dials are refused until Heal.
func (*Cluster) Resolver ¶
Resolver resolves node names of this cluster, for components that dial nodes themselves rather than through a node's Dial. Use it with DialOptions.
func (*Cluster) RestoreNames ¶ added in v0.4.0
RestoreNames lets name reach the global names again. Its KeepOnLoss claims are made again: each holds its name once more, unless another process claimed it meanwhile, which ends the old holder with ReasonNameConflict.
type Names ¶ added in v0.4.0
type Names struct {
// contains filtered or unexported fields
}
Names is an in-memory store of global names, shared by a Cluster's nodes: each node's Config.Names is a view of it (For). It has no lag: a node's Lookup reads the store itself. A node can be cut off from it, as from etcd (Cluster.CutNames): its claims are lost, the names free for the others, and its claims and Resolves fail until it is restored (RestoreNames).
type Option ¶
type Option func(*Cluster)
Option configures a Cluster.
func WithConfig ¶
WithConfig adjusts each node's Config before the node is created, each time it starts (including after Restart): a Registrar, a Membership, hooks for one node only. It runs after WithHooks and WithLogger have set theirs, so what it sets wins, whatever the order of the options.
func WithLogger ¶
WithLogger sets the logger every node uses. Default: discards.