Initial commit
This commit is contained in:
27
Raft.Test/Raft.Test.fsproj
Normal file
27
Raft.Test/Raft.Test.fsproj
Normal file
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="TestServer.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FsCheck" Version="2.16.5" />
|
||||
<PackageReference Include="FsUnit" Version="5.0.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Raft\Raft.fsproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
43
Raft.Test/TestServer.fs
Normal file
43
Raft.Test/TestServer.fs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace Raft.Test
|
||||
|
||||
open Raft
|
||||
open NUnit.Framework
|
||||
open FsUnitTyped
|
||||
|
||||
[<TestFixture>]
|
||||
module TestServer =
|
||||
|
||||
[<Test>]
|
||||
let foo () =
|
||||
let cluster = InMemoryCluster.make<int> 5
|
||||
let logger, logs =
|
||||
let logs = ResizeArray ()
|
||||
let logLine (s : string) =
|
||||
lock logs (fun () ->
|
||||
logs.Add s
|
||||
)
|
||||
let freezeLogs () =
|
||||
lock logs (fun () ->
|
||||
logs |> Seq.toList
|
||||
)
|
||||
logLine, freezeLogs
|
||||
|
||||
let sendMessage = cluster.Servers.[0].OutboundMessageChannel
|
||||
|
||||
// Candidate 1 asks to be elected.
|
||||
|
||||
{
|
||||
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"
|
||||
]
|
Reference in New Issue
Block a user