Fix tests

This commit is contained in:
Marto 2024-02-07 14:47:40 +02:00
parent f5a7813572
commit b4f8fd9999
2 changed files with 11 additions and 22 deletions

View File

@ -395,7 +395,7 @@ func sendToImpl*(sm: var RaftStateMachine, id: RaftNodeId, request: RaftRpcVoteR
sm.output.messages.add(RaftRpcMessage(currentTerm: sm.term, receiver: id, sender: sm.myId, kind: RaftRpcMessageType.VoteReplay, voteReplay: request)) sm.output.messages.add(RaftRpcMessage(currentTerm: sm.term, receiver: id, sender: sm.myId, kind: RaftRpcMessageType.VoteReplay, voteReplay: request))
func sendTo[MsgType](sm: var RaftStateMachine, id: RaftNodeId, request: MsgType) = func sendTo[MsgType](sm: var RaftStateMachine, id: RaftNodeId, request: MsgType) =
sm.debug "Sent to" & $id & $ request sm.debug "Sent to" & $id & $request
if sm.state.isLeader: if sm.state.isLeader:
var follower = sm.findFollowerProggressById(id) var follower = sm.findFollowerProggressById(id)
if follower.isSome: if follower.isSome:

View File

@ -49,10 +49,10 @@ proc advance(tc: var TestCluster, now: times.DateTime) =
for id, node in tc.nodes: for id, node in tc.nodes:
tc.nodes[id].tick(now) tc.nodes[id].tick(now)
var output = tc.nodes[id].poll() var output = tc.nodes[id].poll()
for msg in output.debugLogs: # for msg in output.debugLogs:
echo $msg # echo $msg
for msg in output.messages: for msg in output.messages:
echo "rpc:" & $msg #echo "rpc:" & $msg
tc.nodes[msg.receiver].advance(msg, now) tc.nodes[msg.receiver].advance(msg, now)
@ -71,27 +71,16 @@ proc consensusstatemachineMain*() =
var cluster = createCluster(test_ids_1, times.now()) var cluster = createCluster(test_ids_1, times.now())
echo cluster echo cluster
test "advance empty state machine": test "tick empty state machine":
var sm = RaftStateMachine() var timeNow = times.now()
var msg = sm.createVoteRequest() var config = createConfigFromIds(test_ids_1)
sm.advance(msg, times.now()) var log = initRaftLog(1)
var sm = initRaftStateMachine(test_ids_1[0], 0, log, 0, config, timeNow)
sm.tick(times.now())
echo sm.poll() echo sm.poll()
echo sm.poll() echo sm.poll()
echo getTime() echo getTime()
test "two machines":
var sm = RaftStateMachine()
var sm2 = RaftStateMachine(myId: genUUID())
var msg = sm2.createVoteRequest()
sm.advance(msg, times.now())
echo sm2
echo getTime()
test "something":
var arr = @[1,2,3,4,5]
arr.delete(3..<len(arr))
echo arr
suite "Entry log tests": suite "Entry log tests":
test "append entry as leadeer": test "append entry as leadeer":
var log = initRaftLog(1) var log = initRaftLog(1)
@ -293,7 +282,7 @@ proc consensusstatemachineMain*() =
var timeNow = times.now() var timeNow = times.now()
var sm = initRaftStateMachine(test_ids_1[0], 0, log, 0, config, timeNow) var sm = initRaftStateMachine(test_ids_1[0], 0, log, 0, config, timeNow)
check sm.state.isFollower check sm.state.isFollower
timeNow += 301.milliseconds timeNow += 501.milliseconds
sm.tick(timeNow) sm.tick(timeNow)
check sm.state.isCandidate check sm.state.isCandidate
var output = sm.poll() var output = sm.poll()