This commit is contained in:
Raycho Mukelov 2023-11-05 18:29:28 +02:00
parent 3b3e9b2765
commit 987f4efd99
2 changed files with 6 additions and 4 deletions

View File

@ -14,7 +14,7 @@ import chronicles
type
# Node events
EventType = enum
EventType* = enum
VotingTimeout,
ElectionTimeout,
HeartbeatTimeout,
@ -59,7 +59,7 @@ type
# FSM type constructor
proc new*[RaftNodeState, EventType, NodeType, RaftNodeStates](
T: type ConsensusFsm[RaftNodeState, EventType, NodeType, RaftMessageBase], startSymbol: RaftNodeState): T =
T: type ConsensusFsm[RaftNodeState, EventType, NodeType, RaftMessageBase], startSymbol: RaftNodeState = rnsFollower): T =
result = new(ConsensusFsm[NodeType, EventType, RaftNodeStates])
initRLock(result.mtx)
@ -79,7 +79,7 @@ proc addFsmTransitionLogicalConditions*[RaftNodeState, EventType, NodeType, Raft
fsm: ConsensusFsm[RaftNodeState, EventType, NodeType, RaftMessageBase],
state: RaftNodeState,
event: EventType,
logicalConditions: seq[LogicalCondition[NodeType, Option[RaftMessageBase]]]) =
logicalConditions: seq[LogicalCondition[NodeType, RaftMessageBase]]) =
fsm.logicalFunctionsLut[(state, event)] = logicalConditions

View File

@ -8,10 +8,12 @@
# those terms.
import unittest2
import basic_state_machine
import ../raft/consensus_state_machine
import ../raft/types
suite "Create and test Consensus State Machine":
test "Create Consensus State Machine":
let csm = ConsensusStateMachine.new()
let csm = ConsensusFsm[RaftNodeState, EventType, RaftNode[SmState, SmCommand], RaftMessageBase].new()
check csm != nil