Skip to content

Commit

Permalink
update raft_test TestLeaderElection2AA (talent-plan#159)
Browse files Browse the repository at this point in the history
* update raft_test TestLeaderElection2AA

change expected state to StateCandidate. since implementation of prevote is not required
  • Loading branch information
Lin ZiHao authored May 7, 2020
1 parent 4adae79 commit 189b958
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
5 changes: 0 additions & 5 deletions raft/raft_paper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ func TestLeaderElectionInOneRoundRPC2AA(t *testing.T) {
{5, map[uint64]bool{2: true, 3: true, 4: true}, StateLeader},
{5, map[uint64]bool{2: true, 3: true}, StateLeader},

// return to follower state if it receives vote denial from a majority
{3, map[uint64]bool{2: false, 3: false}, StateFollower},
{5, map[uint64]bool{2: false, 3: false, 4: false, 5: false}, StateFollower},
{5, map[uint64]bool{2: true, 3: false, 4: false, 5: false}, StateFollower},

// stay in candidate if it does not obtain the majority
{3, map[uint64]bool{}, StateCandidate},
{5, map[uint64]bool{2: true}, StateCandidate},
Expand Down
12 changes: 2 additions & 10 deletions raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,16 @@ func TestProgressLeader2AB(t *testing.T) {

func TestLeaderElection2AA(t *testing.T) {
var cfg func(*Config)
candState := StateCandidate
candTerm := uint64(1)
tests := []struct {
*network
state StateType
expTerm uint64
}{
{newNetworkWithConfig(cfg, nil, nil, nil), StateLeader, 1},
{newNetworkWithConfig(cfg, nil, nil, nopStepper), StateLeader, 1},
{newNetworkWithConfig(cfg, nil, nopStepper, nopStepper), candState, candTerm},
{newNetworkWithConfig(cfg, nil, nopStepper, nopStepper, nil), candState, candTerm},
{newNetworkWithConfig(cfg, nil, nopStepper, nopStepper), StateCandidate, 1},
{newNetworkWithConfig(cfg, nil, nopStepper, nopStepper, nil), StateCandidate, 1},
{newNetworkWithConfig(cfg, nil, nopStepper, nopStepper, nil, nil), StateLeader, 1},

// three logs further along than 0, but in the same term so rejections
// are returned instead of the votes being ignored.
{newNetworkWithConfig(cfg,
nil, entsWithConfig(cfg, 1), entsWithConfig(cfg, 1), entsWithConfig(cfg, 1, 1), nil),
StateFollower, 1},
}

for i, tt := range tests {
Expand Down

0 comments on commit 189b958

Please sign in to comment.