Browse Source

raft: fix raft test

Xiang Li 11 years ago
parent
commit
1eb1020717
2 changed files with 15 additions and 15 deletions
  1. 6 6
      raft/raft.go
  2. 9 9
      raft/raft_test.go

+ 6 - 6
raft/raft.go

@@ -93,12 +93,12 @@ func (pr *progress) String() string {
 	return fmt.Sprintf("n=%d m=%d", pr.next, pr.match)
 }
 
-// int64Slice implements sort interface
-type int64Slice []uint64
+// uint64Slice implements sort interface
+type uint64Slice []uint64
 
-func (p int64Slice) Len() int           { return len(p) }
-func (p int64Slice) Less(i, j int) bool { return p[i] < p[j] }
-func (p int64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
+func (p uint64Slice) Len() int           { return len(p) }
+func (p uint64Slice) Less(i, j int) bool { return p[i] < p[j] }
+func (p uint64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
 
 type raft struct {
 	pb.HardState
@@ -247,7 +247,7 @@ func (r *raft) bcastHeartbeat() {
 
 func (r *raft) maybeCommit() bool {
 	// TODO(bmizerany): optimize.. Currently naive
-	mis := make(int64Slice, 0, len(r.prs))
+	mis := make(uint64Slice, 0, len(r.prs))
 	for i := range r.prs {
 		mis = append(mis, r.prs[i].match)
 	}

+ 9 - 9
raft/raft_test.go

@@ -417,9 +417,9 @@ func TestCompact(t *testing.T) {
 		snapd    []byte
 		wpanic   bool
 	}{
-		{1, []uint64{1, 2, 3}, []int64{4, 5}, []byte("some data"), false},
-		{2, []uint64{1, 2, 3}, []int64{4, 5}, []byte("some data"), false},
-		{4, []uint64{1, 2, 3}, []int64{4, 5}, []byte("some data"), true}, // compact out of range
+		{1, []uint64{1, 2, 3}, []uint64{4, 5}, []byte("some data"), false},
+		{2, []uint64{1, 2, 3}, []uint64{4, 5}, []byte("some data"), false},
+		{4, []uint64{1, 2, 3}, []uint64{4, 5}, []byte("some data"), true}, // compact out of range
 	}
 
 	for i, tt := range tests {
@@ -438,14 +438,14 @@ func TestCompact(t *testing.T) {
 					applied:   2,
 					ents:      []pb.Entry{{}, {Term: 1}, {Term: 1}, {Term: 1}},
 				},
-				removed: make(map[int64]bool),
+				removed: make(map[uint64]bool),
 			}
 			for _, r := range tt.removed {
 				sm.removeNode(r)
 			}
 			sm.compact(tt.compacti, tt.nodes, tt.snapd)
-			sort.Sort(int64Slice(sm.raftLog.snapshot.Nodes))
-			sort.Sort(int64Slice(sm.raftLog.snapshot.RemovedNodes))
+			sort.Sort(uint64Slice(sm.raftLog.snapshot.Nodes))
+			sort.Sort(uint64Slice(sm.raftLog.snapshot.RemovedNodes))
 			if sm.raftLog.offset != tt.compacti {
 				t.Errorf("%d: log.offset = %d, want %d", i, sm.raftLog.offset, tt.compacti)
 			}
@@ -915,8 +915,8 @@ func TestRestore(t *testing.T) {
 	}
 	sg := sm.nodes()
 	srn := sm.removedNodes()
-	sort.Sort(int64Slice(sg))
-	sort.Sort(int64Slice(srn))
+	sort.Sort(uint64Slice(sg))
+	sort.Sort(uint64Slice(srn))
 	if !reflect.DeepEqual(sg, s.Nodes) {
 		t.Errorf("sm.Nodes = %+v, want %+v", sg, s.Nodes)
 	}
@@ -1088,7 +1088,7 @@ func TestAddNode(t *testing.T) {
 		t.Errorf("pendingConf = %v, want false", r.pendingConf)
 	}
 	nodes := r.nodes()
-	sort.Sort(int64Slice(nodes))
+	sort.Sort(uint64Slice(nodes))
 	wnodes := []uint64{1, 2}
 	if !reflect.DeepEqual(nodes, wnodes) {
 		t.Errorf("nodes = %v, want %v", nodes, wnodes)