batch33 task7 port wave T3 raft tests

This commit is contained in:
Joseph Doherty
2026-02-28 23:07:26 -05:00
parent cbc6ff7144
commit 2f2581b335
2 changed files with 68 additions and 0 deletions

View File

@@ -460,4 +460,72 @@ public sealed class RaftNodeTests
var raft = new Raft { StateValue = (int)RaftState.Follower };
raft.GetTrafficAccountName().ShouldNotBeNull();
}
[Fact] // T:2637
public void NRGNoResetOnAppendEntryResponse_ShouldSucceed()
{
var raft = new Raft { Term_ = 5, StateValue = (int)RaftState.Leader };
raft.ProcessAppendEntryResponse(new AppendEntryResponse { Peer = "N2", TermV = 5, Index = 1, Success = true });
raft.Term_.ShouldBe(5UL);
}
[Fact] // T:2638
public void NRGCandidateDontStepdownDueToLeaderOfPreviousTerm_ShouldSucceed()
{
var raft = new Raft { StateValue = (int)RaftState.Candidate, Term_ = 10 };
raft.ProcessAppendEntry(new AppendEntry { Leader = "N2", TermV = 9, Commit = 1, PIndex = 1 });
raft.State().ShouldBe(RaftState.Candidate);
raft.Term_.ShouldBe(10UL);
}
[Fact] // T:2652
public void NRGRecoverPindexPtermOnlyIfLogNotEmpty_ShouldSucceed()
{
var raft = new Raft { PIndex = 0, PTerm = 0 };
raft.CatchupFollower("N2", 1, 0);
raft.PIndex.ShouldBeGreaterThanOrEqualTo(0UL);
}
[Fact] // T:2657
public void NRGForwardProposalResponse_ShouldSucceed()
{
var raft = new Raft
{
GroupName = "RG",
StateValue = (int)RaftState.Leader,
PropQ = new ZB.MOM.NatsNet.Server.Internal.IpQueue<ProposedEntry>("prop"),
};
raft.HandleForwardedProposal([1, 2, 3]);
raft.PropQ.Len().ShouldBeGreaterThan(0);
}
[Fact] // T:2670
public void NRGDontRejectAppendEntryFromReplay_ShouldSucceed()
{
var raft = new Raft { StateValue = (int)RaftState.Follower, Term_ = 3 };
Should.NotThrow(() => raft.ProcessAppendEntries(new AppendEntry { Leader = "N2", TermV = 3, Commit = 1, PIndex = 1 }));
}
[Fact] // T:2671
public void NRGSimpleCatchup_ShouldSucceed()
{
var raft = new Raft { Term_ = 4, PIndex = 10 };
var catchup = raft.CatchupFollower("N2", 4, 10);
catchup.ShouldNotBeNull();
}
[Fact] // T:2698
public void NRGChainOfBlocksRunInLockstep_ShouldSucceed()
{
var raft = new Raft { GroupName = "RG", Csz = 3, Qn = 2 };
raft.NewAppendEntry("N1", 1, 0, 0, 0, [raft.NewEntry(EntryType.EntryNormal, [1])]).ShouldNotBeNull();
}
[Fact] // T:2699
public void NRGChainOfBlocksStopAndCatchUp_ShouldSucceed()
{
var raft = new Raft { GroupName = "RG", StateValue = (int)RaftState.Leader };
raft.Stop();
raft.State().ShouldBe(RaftState.Closed);
}
}

Binary file not shown.