Documentation
¶
Overview ¶
Package tests contains integration and helper utilities used across distributed backend tests (non-exported in main module). Lint requires a package comment.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllocatePort ¶ added in v0.4.0
AllocatePort returns a free TCP loopback address ("127.0.0.1:N") for tests that need to bind a server. Listening on :0 lets the kernel pick an unused port; we close immediately and return the address. Two tests calling this concurrently can in theory collide on the same port if the kernel reissues it before either test binds, but in practice the window is too short to matter for our serial-package test runs.
Use this instead of hard-coded ports so that -shuffle and -count=N do not induce flake from port reuse across tests in the same process.
func FindOwnerKey ¶
func FindOwnerKey(b *backend.DistMemory, prefix string, desired []cluster.NodeID, limit int) (string, bool)
FindOwnerKey brute forces keys until it finds one whose owner ordering matches exactly ids.
func StopOnCleanup ¶ added in v0.4.0
func StopOnCleanup(tb testing.TB, b *backend.DistMemory)
StopOnCleanup registers Stop on t.Cleanup so background goroutines (heartbeat, hint-replay, rebalance, autosync, tombstone, gossip) and HTTP listeners do not leak across test iterations under -count=N -race.
nil-tolerant: if the backend creation failed, this is a no-op so callers can keep the existing pattern of `b, _ := backend.NewDistMemory(...)`.
Types ¶
type DistCluster ¶ added in v0.4.1
type DistCluster struct {
Ring *cluster.Ring
Membership *cluster.Membership
Transport *backend.InProcessTransport
Nodes []*backend.DistMemory
}
DistCluster bundles the in-process distributed-memory test fixture: a single shared Ring + Membership + Transport, and N DistMemory backends already wired into them. Most multi-node tests in this package follow the identical setup — extracting it as a helper keeps each test under the function-length budget and removes copy-paste drift.
func SetupInProcessCluster ¶ added in v0.4.1
func SetupInProcessCluster(tb testing.TB, n int, opts ...backend.DistMemoryOption) *DistCluster
SetupInProcessCluster is shorthand for SetupInProcessClusterRF with the default replication factor.
func SetupInProcessClusterRF ¶ added in v0.4.1
func SetupInProcessClusterRF(tb testing.TB, n, replication int, opts ...backend.DistMemoryOption) *DistCluster
SetupInProcessClusterRF is the explicit-replication-factor variant of SetupInProcessCluster — used by tests that need 2-node clusters or non-default replica counts.
func (*DistCluster) ByID ¶ added in v0.4.1
func (c *DistCluster) ByID(id cluster.NodeID) *backend.DistMemory
ByID returns the node with the given ID, or nil if not present. Tests frequently need to look up a node by the ID returned from ring.Lookup — this avoids the manual `map[NodeID]*DistMemory{...}` lookup pattern that the dist_*_test.go files used to inline.