diff --git a/Raft.Test/TestInMemoryServer.fs b/Raft.Test/TestInMemoryServer.fs index 9feb209..0e6179c 100644 --- a/Raft.Test/TestInMemoryServer.fs +++ b/Raft.Test/TestInMemoryServer.fs @@ -9,57 +9,6 @@ open FsCheck [] module TestInMemoryServer = - [] - let ``Startup sequence, first fumbling steps`` () = - let cluster, network = InMemoryCluster.make 5 - - let logger, logs = TestLogger.make () - - // Candidate 1 asks server 0 to vote for it. - - { - CandidateTerm = 0 - CandidateId = 1 - ReplyChannel = fun message -> logger (sprintf "Received message for term %i" message.VoterTerm) - CandidateLastLogEntry = None - } - |> Instruction.RequestVote - |> Message.Instruction - |> cluster.SendMessageDirectly 0 - - 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 - CandidateId = 1 - ReplyChannel = fun message -> logger (sprintf "Received message for term %i" message.VoterTerm) - CandidateLastLogEntry = None - } - |> Instruction.RequestVote - |> Message.Instruction - |> cluster.SendMessageDirectly 0 - - 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 - CandidateId = 2 - ReplyChannel = fun _ -> Interlocked.Increment calls |> ignore - CandidateLastLogEntry = None - } - |> Instruction.RequestVote - |> Message.Instruction - |> cluster.SendMessageDirectly 0 - - calls.Value |> shouldEqual 0 - [] let ``Startup sequence in prod, only one timeout takes place`` () = let cluster, network = InMemoryCluster.make 5 diff --git a/Raft/Server.fs b/Raft/Server.fs index 2ea300c..946187a 100644 --- a/Raft/Server.fs +++ b/Raft/Server.fs @@ -75,7 +75,6 @@ type RequestVoteMessage = CandidateTerm : int CandidateId : int CandidateLastLogEntry : LogEntryMetadata option - ReplyChannel : RequestVoteReply -> unit } override this.ToString () = @@ -381,7 +380,9 @@ type Server<'a> VoteGranted = true Candidate = message.CandidateId } - |> message.ReplyChannel + |> Reply.RequestVoteReply + |> Message.Reply + |> messageChannel message.CandidateId | AppendEntries message -> // This was guaranteed above. @@ -695,7 +696,6 @@ type Server<'a> CandidateTerm = persistentState.CurrentTerm CandidateId = me CandidateLastLogEntry = persistentState.GetLastLogEntry () |> Option.map snd - ReplyChannel = fun reply -> messageChannel me (RequestVoteReply reply |> Message.Reply) } |> Instruction.RequestVote |> Message.Instruction