Skip to content

Commit

Permalink
test LeaderRemoval while doing Apply's
Browse files Browse the repository at this point in the history
  • Loading branch information
superfell committed Jan 18, 2016
1 parent d136cd1 commit 6b57497
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ CHECK:
if len(first.logs) != len(fsm.logs) {
fsm.Unlock()
if time.Now().After(limit) {
t.Fatalf("length mismatch: %d %d",
t.Fatalf("FSM log length mismatch: %d %d",
len(first.logs), len(fsm.logs))
} else {
goto WAIT
Expand Down Expand Up @@ -905,8 +905,18 @@ func TestRaft_RemoveLeader_NoShutdown(t *testing.T) {
leader := c.Leader()

// Remove the leader
leader.RemovePeer(leader.localAddr)
var removeFuture Future
for i := byte(0) ; i < 100; i++ {
leader.Apply([]byte{i}, 0)
if i == 80 {
removeFuture = leader.RemovePeer(leader.localAddr)
}
}

if err := removeFuture.Error(); err != nil {
t.Fatalf("RemovePeer failed with error %v", err)
}

// Wait a while
time.Sleep(20 * time.Millisecond)

Expand All @@ -930,6 +940,9 @@ func TestRaft_RemoveLeader_NoShutdown(t *testing.T) {
if peers, _ := leader.peerStore.Peers(); len(peers) != 1 {
t.Fatalf("leader should have no peers")
}

// Other nodes should have the same state
c.EnsureSame(t)
}

func TestRaft_RemoveLeader_SplitCluster(t *testing.T) {
Expand Down

0 comments on commit 6b57497

Please sign in to comment.