Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Replace t.error/fatal with assert/request in [raft_flow_control_test.go] #185

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions raft_flow_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package raft
import (
"testing"

"github.com/stretchr/testify/require"

pb "go.etcd.io/raft/v3/raftpb"
)

Expand All @@ -36,23 +38,18 @@ func TestMsgAppFlowControlFull(t *testing.T) {
for i := 0; i < r.trk.MaxInflight; i++ {
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}})
ms := r.readMessages()
if len(ms) != 1 || ms[0].Type != pb.MsgApp {
t.Fatalf("#%d: len(ms) = %d, want 1 MsgApp", i, len(ms))
}
require.Len(t, ms, 1)
require.Equal(t, pb.MsgApp, ms[0].Type)
}

// ensure 1
if !pr2.IsPaused() {
t.Fatal("paused = false, want true")
}
require.True(t, pr2.IsPaused())

// ensure 2
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))
}
require.Empty(t, ms)
}
}

Expand Down Expand Up @@ -84,21 +81,16 @@ func TestMsgAppFlowControlMoveForward(t *testing.T) {
// fill in the inflights window again
r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("somedata")}}})
ms := r.readMessages()
if len(ms) != 1 || ms[0].Type != pb.MsgApp {
t.Fatalf("#%d: len(ms) = %d, want 1 MsgApp", tt, len(ms))
}
require.Len(t, ms, 1)
require.Equal(t, pb.MsgApp, ms[0].Type)

// ensure 1
if !pr2.IsPaused() {
t.Fatalf("#%d: paused = false, want true", tt)
}
require.True(t, pr2.IsPaused())

// ensure 2
for i := 0; i < tt; i++ {
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgAppResp, Index: uint64(i)})
if !pr2.IsPaused() {
t.Fatalf("#%d.%d: paused = false, want true", tt, i)
}
require.True(t, pr2.IsPaused())
}
}
}
Expand All @@ -122,27 +114,21 @@ func TestMsgAppFlowControlRecvHeartbeat(t *testing.T) {
for tt := 1; tt < 5; tt++ {
// recv tt msgHeartbeatResp and expect one free slot
for i := 0; i < tt; i++ {
if !pr2.IsPaused() {
t.Fatalf("#%d.%d: paused = false, want true", tt, i)
}
require.True(t, pr2.IsPaused())
// Unpauses the progress, sends an empty MsgApp, and pauses it again.
r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgHeartbeatResp})
ms := r.readMessages()
if len(ms) != 1 || ms[0].Type != pb.MsgApp || len(ms[0].Entries) != 0 {
t.Fatalf("#%d.%d: len(ms) == %d, want 1 empty MsgApp", tt, i, len(ms))
}
require.Len(t, ms, 1)
require.Equal(t, pb.MsgApp, ms[0].Type)
require.Empty(t, ms[0].Entries)
}

// No more appends are sent if there are no heartbeats.
for i := 0; i < 10; i++ {
if !pr2.IsPaused() {
t.Fatalf("#%d.%d: paused = false, want true", tt, i)
}
require.True(t, pr2.IsPaused())
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.%d: len(ms) = %d, want 0", tt, i, len(ms))
}
require.Empty(t, ms)
}

// clear all pending messages.
Expand Down
Loading