Browse Source

Merge pull request #6541 from hhkbp2/improve-test-coverage

raft: add test cases to improve test coverage
Xiang Li 9 năm trước cách đây
mục cha
commit
3807faeddf
2 tập tin đã thay đổi với 17 bổ sung8 xóa
  1. 5 0
      raft/log_unstable_test.go
  2. 12 8
      raft/raft_test.go

+ 5 - 0
raft/log_unstable_test.go

@@ -156,6 +156,11 @@ func TestUnstableMaybeTerm(t *testing.T) {
 			4,
 			true, 1,
 		},
+		{
+			[]pb.Entry{{Index: 5, Term: 1}}, 5, &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 4, Term: 1}},
+			3,
+			false, 0,
+		},
 		{
 			[]pb.Entry{}, 5, &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 4, Term: 1}},
 			5,

+ 12 - 8
raft/raft_test.go

@@ -1434,10 +1434,12 @@ func TestReadOnlyOptionSafe(t *testing.T) {
 		wri       uint64
 		wctx      []byte
 	}{
-		{b, 10, 11, []byte("ctx1")},
-		{c, 10, 21, []byte("ctx2")},
-		{b, 10, 31, []byte("ctx3")},
-		{c, 10, 41, []byte("ctx4")},
+		{a, 10, 11, []byte("ctx1")},
+		{b, 10, 21, []byte("ctx2")},
+		{c, 10, 31, []byte("ctx3")},
+		{a, 10, 41, []byte("ctx4")},
+		{b, 10, 51, []byte("ctx5")},
+		{c, 10, 61, []byte("ctx6")},
 	}
 
 	for i, tt := range tests {
@@ -1492,10 +1494,12 @@ func TestReadOnlyOptionLease(t *testing.T) {
 		wri       uint64
 		wctx      []byte
 	}{
-		{b, 10, 11, []byte("ctx1")},
-		{c, 10, 21, []byte("ctx2")},
-		{b, 10, 31, []byte("ctx3")},
-		{c, 10, 41, []byte("ctx4")},
+		{a, 10, 11, []byte("ctx1")},
+		{b, 10, 21, []byte("ctx2")},
+		{c, 10, 31, []byte("ctx3")},
+		{a, 10, 41, []byte("ctx4")},
+		{b, 10, 51, []byte("ctx5")},
+		{c, 10, 61, []byte("ctx6")},
 	}
 
 	for i, tt := range tests {