raftSimTest
fun raftSimTest(n: Int = 3, baseConfig: RaftConfig = MULTI_NODE_SIM_BASE_CONFIG, baseSeed: Long = MULTI_NODE_SIM_SEED, timeout: Duration = 5.seconds, body: suspend TestScope.(MultiNodeRaftSim) -> Unit): TestResult
Build a MultiNodeRaftSim of n voters and run body under runTest(StandardTestDispatcher(), timeout = 5.seconds) — the canonical harness for multi-node Raft tests. See MultiNodeRaftSim for the full determinism contract.
@Test
fun leaderElected() = raftSimTest(n = 3) { sim ->
val leader = sim.awaitLeader()
assertNotNull(leader)
}
@Test
fun partitionAndRecover() = raftSimTest(n = 3) { sim ->
sim.awaitLeader()
val leaderId = sim.leader()!!.let { l ->
sim.nodes.entries.first { it.value === l }.key
}
sim.partitionOff(leaderId)
val survivors = sim.nodeIds.filter { it != leaderId }.toSet()
sim.awaitLeader(among = survivors)
sim.heal()
// The old leader rejoins as a follower
sim.awaitRole(leaderId, RaftRole.Follower)
}Content copied to clipboard
Parameters
n
Number of voters (default 3 — minimum for fault tolerance with one crash).
baseConfig
Timing config forwarded to MultiNodeRaftSim. Defaults to MULTI_NODE_SIM_BASE_CONFIG.
baseSeed
Seed for per-node Random derivation. Defaults to MULTI_NODE_SIM_SEED.
timeout
Test timeout. Default 5 s — tight enough to surface hangs quickly. Widen only for tests that intentionally wait on multi-round operations (e.g. large-log compaction).