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 [/rafttest] #189

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions rafttest/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

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

Expand Down Expand Up @@ -45,9 +47,8 @@ func TestNetworkDrop(t *testing.T) {
}

drop := sent - received
if drop > int((droprate+0.1)*float64(sent)) || drop < int((droprate-0.1)*float64(sent)) {
t.Errorf("drop = %d, want around %.2f", drop, droprate*float64(sent))
}
assert.LessOrEqual(t, drop, int((droprate+0.1)*float64(sent)))
assert.GreaterOrEqual(t, drop, int((droprate-0.1)*float64(sent)))
}

func TestNetworkDelay(t *testing.T) {
Expand All @@ -66,7 +67,5 @@ func TestNetworkDelay(t *testing.T) {

w := time.Duration(float64(sent)*delayrate/2) * delay
// there is some overhead in the send call since it generates random numbers.
if total < w {
t.Errorf("total = %v, want > %v", total, w)
}
assert.GreaterOrEqual(t, total, w)
}
14 changes: 5 additions & 9 deletions rafttest/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

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

Expand All @@ -39,9 +41,7 @@ func TestBasicProgress(t *testing.T) {
nodes[0].Propose(context.TODO(), []byte("somedata"))
}

if !waitCommitConverge(nodes, 100) {
t.Errorf("commits failed to converge!")
}
assert.True(t, waitCommitConverge(nodes, 100))

for _, n := range nodes {
n.stop()
Expand Down Expand Up @@ -79,9 +79,7 @@ func TestRestart(t *testing.T) {
}
nodes[k1].restart()

if !waitCommitConverge(nodes, 120) {
t.Errorf("commits failed to converge!")
}
assert.True(t, waitCommitConverge(nodes, 120))

for _, n := range nodes {
n.stop()
Expand Down Expand Up @@ -118,9 +116,7 @@ func TestPause(t *testing.T) {
}
nodes[1].resume()

if !waitCommitConverge(nodes, 120) {
t.Errorf("commits failed to converge!")
}
assert.True(t, waitCommitConverge(nodes, 120))

for _, n := range nodes {
n.stop()
Expand Down
Loading