grpcproctest

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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 New

func New(t testing.TB, names ...string) *Cluster

New starts one node per name and stops them all when the test ends.

func NewWith

func NewWith(t testing.TB, opts []Option, names ...string) *Cluster

NewWith is New with options.

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

func (c *Cluster) CutNames(name string)

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

func (c *Cluster) Heal(a, b string)

Heal lets a and b reach each other again.

func (*Cluster) Kill

func (c *Cluster) Kill(name string)

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

func (c *Cluster) Names() *Names

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

func (c *Cluster) Node(name string) *grpcproc.Node

Node returns the running node called name.

func (*Cluster) Partition

func (c *Cluster) Partition(a, b string)

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

func (*Cluster) Resolver() grpcproc.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) Restart

func (c *Cluster) Restart(name string) *grpcproc.Node

Restart starts a stopped or killed node again, with a new incarnation.

func (*Cluster) RestoreNames added in v0.4.0

func (c *Cluster) RestoreNames(name string)

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.

func (*Cluster) Stop

func (c *Cluster) Stop(name string)

Stop stops name gracefully: watchers of its processes get Down{shutdown}, or Down{noconnection} if a Partition breaks their link meanwhile.

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

func NewNames added in v0.4.0

func NewNames() *Names

NewNames returns an empty store.

func (*Names) For added in v0.4.0

func (s *Names) For(node string) grpcproc.Names

For is the view of the store a node named node uses as its Config.Names.

func (*Names) List added in v0.4.0

func (s *Names) List(prefix string, limit int) []grpcproc.GlobalName

List returns the names with prefix, ordered by name, at most limit unless limit is 0.

type Option

type Option func(*Cluster)

Option configures a Cluster.

func WithConfig

func WithConfig(fn func(name string, cfg *grpcproc.Config)) Option

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 WithHooks

func WithHooks(h grpcproc.Hooks) Option

WithHooks installs h on every node.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger every node uses. Default: discards.

func WithServices

func WithServices(fn func(n *grpcproc.Node, s *grpc.Server)) Option

WithServices registers extra gRPC services on every node's server, such as an Inspector, each time the node starts (including after Restart).

Jump to

Keyboard shortcuts

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