MultiNodeRaftSim
Multi-node Raft simulation harness for use in tests. See the file-level KDoc for the full determinism contract and setup ceremony.
Parameters
The ordered list of voter NodeIds forming the initial cluster config.
The test's TestScope — used for withTimeout bounds in the await helpers.
Scope for node coroutines — pass TestScope.backgroundScope so the infinite heartbeat/election loops are cancelled at test teardown without kotlinx.coroutines.test.UncompletedCoroutinesError.
Timing parameters for every node. RaftConfig.random is overridden per node (Random(baseSeed + nodeIndex)) to ensure distinct election timeouts and guarantee convergence. Must have RaftConfig.expectVirtualTime = true for tests running under a kotlinx.coroutines.test.TestDispatcher. Defaults to MULTI_NODE_SIM_BASE_CONFIG.
Seed from which per-node Randoms are derived. Change to explore different election orderings; the default MULTI_NODE_SIM_SEED is stable across runs.
Optional payload cap forwarded to MultiNodeRaftNetwork — forces InstallSnapshot chunking in tests that exercise the snapshot-transfer path.
Override to wire a custom RaftNode implementation. The default wires CoroutineScope.raftNode with a per-node seeded config. Parameters: (id, transport, storage, childScope).
Constructors
Properties
Functions
The applied state for id — ordered concatenation of committed commands, reset on a snapshot install. Two nodes with equal applied state have applied the same sequence of commands.
Suspend until some node is RaftRole.Leader; return it, or fail fast with a state dump.
Suspend until a node whose id is in among is RaftRole.Leader. Use after a partition when a stale leader from the minority partition may transiently report leader status — scope the await to the surviving voters.
Assert election safety (at most one leader at a time) and state-machine safety (no two nodes committed different commands at the same log index up to the minimum known commit).
Render a per-node diagnostic snapshot — roles, terms, commit indices, log ranges, and an election-event histogram (Timeout / BecomeLeader / BecomeFollower) that makes leadership thrash and term inflation visible at a glance. Used as the body of the AssertionError thrown by the bounded await helpers on non-convergence, and callable directly from a failing test assertion.
All nodes currently reporting RaftRole.Follower.
Propose against the current leader, re-acquiring and retrying on NotLeaderException. Returns the committed us.tractat.kuilt.raft.LogEntry. Restricts to among if provided.
Let pending work at the current virtual instant drain without advancing the clock. Under StandardTestDispatcher's FIFO scheduling, yielding hands the single test thread back so already-scheduled coroutines (e.g. a freshly launched collector) run at this instant. Call after launching a collector you need to observe the next emission.