mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add TestUnstableStableTo
This commit is contained in:
parent
7703d4942c
commit
37ab463e86
@ -208,3 +208,87 @@ func TestUnstableRestore(t *testing.T) {
|
||||
t.Errorf("snap = %v, want %v", u.snapshot, &s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnstableStableTo(t *testing.T) {
|
||||
tests := []struct {
|
||||
entries []pb.Entry
|
||||
offset uint64
|
||||
snap *pb.Snapshot
|
||||
index, term uint64
|
||||
|
||||
woffset uint64
|
||||
wlen int
|
||||
}{
|
||||
{
|
||||
[]pb.Entry{}, 0, nil,
|
||||
5, 1,
|
||||
0, 0,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 1}}, 5, nil,
|
||||
5, 1, // stable to the first entry
|
||||
6, 0,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 1}, {Index: 6, Term: 1}}, 5, nil,
|
||||
5, 1, // stable to the first entry
|
||||
6, 1,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 6, Term: 2}}, 5, nil,
|
||||
6, 1, // stable to the first entry and term mismatch
|
||||
5, 1,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 1}}, 5, nil,
|
||||
4, 1, // stable to old entry
|
||||
5, 1,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 1}}, 5, nil,
|
||||
4, 2, // stable to old entry
|
||||
5, 1,
|
||||
},
|
||||
// with snapshot
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 1}}, 5, &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 4, Term: 1}},
|
||||
5, 1, // stable to the first entry
|
||||
6, 0,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 1}, {Index: 6, Term: 1}}, 5, &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 4, Term: 1}},
|
||||
5, 1, // stable to the first entry
|
||||
6, 1,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 6, Term: 2}}, 5, &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 5, Term: 1}},
|
||||
6, 1, // stable to the first entry and term mismatch
|
||||
5, 1,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 1}}, 5, &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 4, Term: 1}},
|
||||
4, 1, // stable to snapshot
|
||||
5, 1,
|
||||
},
|
||||
{
|
||||
[]pb.Entry{{Index: 5, Term: 2}}, 5, &pb.Snapshot{Metadata: pb.SnapshotMetadata{Index: 4, Term: 2}},
|
||||
4, 1, // stable to old entry
|
||||
5, 1,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
u := unstable{
|
||||
entries: tt.entries,
|
||||
offset: tt.offset,
|
||||
snapshot: tt.snap,
|
||||
}
|
||||
u.stableTo(tt.index, tt.term)
|
||||
if u.offset != tt.woffset {
|
||||
t.Errorf("#%d: offset = %d, want %d", i, u.offset, tt.woffset)
|
||||
}
|
||||
if len(u.entries) != tt.wlen {
|
||||
t.Errorf("#%d: len = %d, want %d", i, len(u.entries), tt.wlen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user