Skip to content

Commit

Permalink
Merge pull request #189 from MrDXY/replace-test-errors-with-assert-ra…
Browse files Browse the repository at this point in the history
…fttest

Test: Replace t.error/fatal with assert/request in [/rafttest]
  • Loading branch information
ahrtr authored Mar 28, 2024
2 parents ebcf5af + 2a5cc24 commit a02bb0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
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

0 comments on commit a02bb0f

Please sign in to comment.