Skip to content

Commit

Permalink
raft: fix flow control tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Kalinnikov <[email protected]>
  • Loading branch information
pav-kv committed Oct 27, 2022
1 parent 9db31b8 commit 8bf78f9
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions raft/raft_flow_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
}
}
}
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 8bf78f9

Please sign in to comment.