diff --git a/raft/raft_flow_control_test.go b/raft/raft_flow_control_test.go index 5430568c3e2f..43644dccdb80 100644 --- a/raft/raft_flow_control_test.go +++ b/raft/raft_flow_control_test.go @@ -21,8 +21,8 @@ import ( ) // TestMsgAppFlowControlFull ensures: -// 1. msgApp can fill the sending window until full -// 2. when the window is full, no more msgApp can be sent. +// 1. MsgApp can fill the sending window until full +// 2. when the window is full, no more entries can be sent through MsgApp. func TestMsgAppFlowControlFull(t *testing.T) { r := newTestRaft(1, 5, 1, newTestMemoryStorage(withPeers(1, 2))) @@ -50,8 +50,8 @@ func TestMsgAppFlowControlFull(t *testing.T) { for i := 0; i < 10; i++ { r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}}) ms := r.readMessages() - if len(ms) != 0 { - t.Fatalf("#%d: len(ms) = %d, want 0", i, len(ms)) + if len(ms) != 1 || len(ms[0].Entries) != 0 { + t.Fatalf("#%d: len(ms) = %d, want 1 empty message", i, len(ms)) } } } @@ -128,24 +128,16 @@ func TestMsgAppFlowControlRecvHeartbeat(t *testing.T) { for i := 0; i < tt; i++ { r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgHeartbeatResp}) r.readMessages() - if pr2.Inflights.Full() { - t.Fatalf("#%d.%d: inflights.full = %t, want %t", tt, i, pr2.Inflights.Full(), false) - } } - - // one slot - r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}}) - ms := r.readMessages() - if len(ms) != 1 { - t.Fatalf("#%d: free slot = 0, want 1", tt) + if !pr2.Inflights.Full() { + t.Fatalf("#%d: inflights.full = %t, want %t", tt, pr2.Inflights.Full(), true) } - // and just one slot for i := 0; i < 10; i++ { r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}}) - ms1 := r.readMessages() - if len(ms1) != 0 { - t.Fatalf("#%d.%d: len(ms) = %d, want 0", tt, i, len(ms1)) + ms := r.readMessages() + if len(ms) != 1 || len(ms[0].Entries) != 0 { + t.Fatalf("#%d: free slot = 0, want 1", tt) } }