Move to mutable state
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace Raft.Test
|
||||
|
||||
open System.Threading
|
||||
open Raft
|
||||
open NUnit.Framework
|
||||
open FsUnitTyped
|
||||
@@ -22,7 +23,7 @@ module TestServer =
|
||||
|
||||
let sendMessage = cluster.Servers.[0].OutboundMessageChannel
|
||||
|
||||
// Candidate 1 asks to be elected.
|
||||
// Candidate 1 asks server 0 to vote for it.
|
||||
|
||||
{
|
||||
CandidateTerm = 0<Term>
|
||||
@@ -34,3 +35,32 @@ module TestServer =
|
||||
|> sendMessage 0<ServerId>
|
||||
|
||||
logs () |> shouldEqual [ "Received message for term 0" ]
|
||||
|
||||
// Candidate 1 asks to be elected again! This is fine, maybe the network is replaying requests
|
||||
// and the network swallowed our reply, so we should reply in the same way.
|
||||
{
|
||||
CandidateTerm = 0<Term>
|
||||
CandidateId = 1<ServerId>
|
||||
ReplyChannel = fun message -> logger (sprintf "Received message for term %i" message.VoterTerm)
|
||||
CandidateLastLogEntry = 0<LogIndex>, 0<Term>
|
||||
}
|
||||
|> Message.RequestVote
|
||||
|> sendMessage 0<ServerId>
|
||||
|
||||
logs ()
|
||||
|> shouldEqual [ "Received message for term 0" ; "Received message for term 0" ]
|
||||
|
||||
// Candidate 2 asks to be elected. We won't vote for them, because we've already voted.
|
||||
// and the network swallowed our reply, so we should reply in the same way.
|
||||
let calls = ref 0
|
||||
|
||||
{
|
||||
CandidateTerm = 0<Term>
|
||||
CandidateId = 2<ServerId>
|
||||
ReplyChannel = fun _ -> Interlocked.Increment calls |> ignore
|
||||
CandidateLastLogEntry = 0<LogIndex>, 0<Term>
|
||||
}
|
||||
|> Message.RequestVote
|
||||
|> sendMessage 0<ServerId>
|
||||
|
||||
calls.Value |> shouldEqual 0
|
||||
|
Reference in New Issue
Block a user