mirror of
https://github.com/talent-plan/tinykv.git
synced 2024-12-26 12:50:11 +08:00
ut: add TestRestoreFromSnapWithOverlapingPeersMsg2C (#408)
This commit is contained in:
parent
e7de6af1d4
commit
6ecddc7f00
@ -1094,6 +1094,35 @@ func TestRestoreFromSnapMsg2C(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRestoreFromSnapWithOverlapingPeersMsg2C(t *testing.T) {
|
||||||
|
s := pb.Snapshot{
|
||||||
|
Metadata: &pb.SnapshotMetadata{
|
||||||
|
Index: 11, // magic number
|
||||||
|
Term: 11, // magic number
|
||||||
|
ConfState: &pb.ConfState{Nodes: []uint64{2, 3, 4}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
m := pb.Message{MsgType: pb.MessageType_MsgSnapshot, From: 1, Term: 2, Snapshot: &s}
|
||||||
|
|
||||||
|
sm := newTestRaft(2, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage())
|
||||||
|
sm.Step(m)
|
||||||
|
|
||||||
|
if sm.Lead != uint64(1) {
|
||||||
|
t.Errorf("sm.Lead = %d, want 1", sm.Lead)
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes := s.Metadata.ConfState.Nodes
|
||||||
|
if len(nodes) != len(sm.Prs) {
|
||||||
|
t.Errorf("len(sm.Prs) = %d, want %d", len(sm.Prs), len(nodes))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range nodes {
|
||||||
|
if _, ok := sm.Prs[p]; !ok {
|
||||||
|
t.Errorf("missing peer %d", p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSlowNodeRestore2C(t *testing.T) {
|
func TestSlowNodeRestore2C(t *testing.T) {
|
||||||
nt := newNetwork(nil, nil, nil)
|
nt := newNetwork(nil, nil, nil)
|
||||||
nt.send(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgHup})
|
nt.send(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgHup})
|
||||||
|
Loading…
Reference in New Issue
Block a user