Browse Source

raft: add leader change test for configuration

Xiang Li 11 years ago
parent
commit
cc3a8e26c8
1 changed files with 25 additions and 0 deletions
  1. 25 0
      raft/raft_test.go

+ 25 - 0
raft/raft_test.go

@@ -515,6 +515,31 @@ func TestConf(t *testing.T) {
 	}
 }
 
+// Ensures that the new leader sets the pendingConf flag correctly according to
+// the uncommitted log entries
+func TestConfChangeLeader(t *testing.T) {
+	tests := []struct {
+		et       int
+		wPending bool
+	}{
+		{normal, false},
+		{configAdd, true},
+		{configRemove, true},
+	}
+
+	for i, tt := range tests {
+		sm := newStateMachine(0, []int{0})
+		sm.log = &log{ents: []Entry{{}, {Type: tt.et}}}
+
+		sm.becomeCandidate()
+		sm.becomeLeader()
+
+		if sm.pendingConf != tt.wPending {
+			t.Errorf("#%d: pendingConf = %v, want %v", i, sm.pendingConf, tt.wPending)
+		}
+	}
+}
+
 func TestAllServerStepdown(t *testing.T) {
 	tests := []stateType{stateFollower, stateCandidate, stateLeader}