grpcproctest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 15 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

This section is empty.

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) 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) 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 (an Inspector built with inspect.WithResolver). 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) Stop

func (c *Cluster) Stop(name string)

Stop stops name gracefully: watchers of its processes get Down{shutdown}.

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.

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