mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add tests for ignoring heartbeat reply
This commit is contained in:
parent
09e9618b02
commit
507300130b
@ -778,16 +778,22 @@ func TestAllServerStepdown(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLeaderAppResp(t *testing.T) {
|
func TestLeaderAppResp(t *testing.T) {
|
||||||
|
// initial progress: match = 0; netx = 3
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
index uint64
|
index uint64
|
||||||
reject bool
|
reject bool
|
||||||
|
// progress
|
||||||
|
wmatch uint64
|
||||||
|
wnext uint64
|
||||||
|
// message
|
||||||
wmsgNum int
|
wmsgNum int
|
||||||
windex uint64
|
windex uint64
|
||||||
wcommitted uint64
|
wcommitted uint64
|
||||||
}{
|
}{
|
||||||
{3, true, 0, 0, 0}, // stale resp; no replies
|
{3, true, 0, 3, 0, 0, 0}, // stale resp; no replies
|
||||||
{2, true, 1, 1, 0}, // denied resp; leader does not commit; decrese next and send probing msg
|
{2, true, 0, 2, 1, 1, 0}, // denied resp; leader does not commit; decrese next and send probing msg
|
||||||
{2, false, 2, 2, 2}, // accept resp; leader commits; broadcast with commit index
|
{2, false, 2, 3, 2, 2, 2}, // accept resp; leader commits; broadcast with commit index
|
||||||
|
{0, false, 0, 3, 0, 0, 0}, // ignore heartbeat replies
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
@ -799,6 +805,15 @@ func TestLeaderAppResp(t *testing.T) {
|
|||||||
sm.becomeLeader()
|
sm.becomeLeader()
|
||||||
sm.ReadMessages()
|
sm.ReadMessages()
|
||||||
sm.Step(pb.Message{From: 2, Type: pb.MsgAppResp, Index: tt.index, Term: sm.Term, Reject: tt.reject})
|
sm.Step(pb.Message{From: 2, Type: pb.MsgAppResp, Index: tt.index, Term: sm.Term, Reject: tt.reject})
|
||||||
|
|
||||||
|
p := sm.prs[2]
|
||||||
|
if p.match != tt.wmatch {
|
||||||
|
t.Errorf("#%d match = %d, want %d", i, p.match, tt.wmatch)
|
||||||
|
}
|
||||||
|
if p.next != tt.wnext {
|
||||||
|
t.Errorf("#%d next = %d, want %d", i, p.next, tt.wnext)
|
||||||
|
}
|
||||||
|
|
||||||
msgs := sm.ReadMessages()
|
msgs := sm.ReadMessages()
|
||||||
|
|
||||||
if len(msgs) != tt.wmsgNum {
|
if len(msgs) != tt.wmsgNum {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user