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 [/confchange] #186

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
28 changes: 10 additions & 18 deletions confchange/quick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package confchange

import (
"fmt"
"math/rand"
"reflect"
"testing"
"testing/quick"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)
Expand Down Expand Up @@ -48,10 +50,8 @@ func TestConfChangeQuick(t *testing.T) {
return err
}
cfg2a.AutoLeave = false
if !reflect.DeepEqual(cfg, cfg2a) || !reflect.DeepEqual(trk, trk2a) {
return fmt.Errorf("cfg: %+v\ncfg2a: %+v\ntrk: %+v\ntrk2a: %+v",
cfg, cfg2a, trk, trk2a)
}
assert.Equal(t, cfg, cfg2a)
assert.Equal(t, trk, trk2a)
c.Tracker.Config = cfg
c.Tracker.Progress = trk
cfg2b, trk2b, err := c.LeaveJoint()
Expand All @@ -65,10 +65,8 @@ func TestConfChangeQuick(t *testing.T) {
if err != nil {
return err
}
if !reflect.DeepEqual(cfg, cfg2b) || !reflect.DeepEqual(trk, trk2b) {
return fmt.Errorf("cfg: %+v\ncfg2b: %+v\ntrk: %+v\ntrk2b: %+v",
cfg, cfg2b, trk, trk2b)
}
assert.Equal(t, cfg, cfg2b)
assert.Equal(t, trk, trk2b)
c.Tracker.Config = cfg
c.Tracker.Progress = trk
return nil
Expand Down Expand Up @@ -107,9 +105,7 @@ func TestConfChangeQuick(t *testing.T) {
var n int
f1 := func(setup initialChanges, ccs confChanges) *Changer {
c, err := wrapper(runWithSimple)(setup, ccs)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if n < infoCount {
t.Log("initial setup:", Describe(setup...))
t.Log("changes:", Describe(ccs...))
Expand All @@ -121,19 +117,15 @@ func TestConfChangeQuick(t *testing.T) {
}
f2 := func(setup initialChanges, ccs confChanges) *Changer {
c, err := wrapper(runWithJoint)(setup, ccs)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
return c
}
err := quick.CheckEqual(f1, f2, cfg)
if err == nil {
return
}
cErr, ok := err.(*quick.CheckEqualError)
if !ok {
t.Fatal(err)
}
require.True(t, ok, err)

t.Error("setup:", Describe(cErr.In[0].([]pb.ConfChangeSingle)...))
t.Error("ccs:", Describe(cErr.In[1].([]pb.ConfChangeSingle)...))
Expand Down
16 changes: 6 additions & 10 deletions confchange/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"
"testing/quick"

"github.com/stretchr/testify/assert"

pb "go.etcd.io/raft/v3/raftpb"
"go.etcd.io/raft/v3/tracker"
)
Expand Down Expand Up @@ -90,8 +92,7 @@ func TestRestore(t *testing.T) {
LastIndex: 10,
}
cfg, trk, err := Restore(chg, cs)
if err != nil {
t.Error(err)
if !assert.NoError(t, err) {
return false
}
chg.Tracker.Config = cfg
Expand All @@ -109,12 +110,9 @@ func TestRestore(t *testing.T) {
cs2 := chg.Tracker.ConfState()
// NB: cs.Equivalent does the same "sorting" dance internally, but let's
// test it a bit here instead of relying on it.
if reflect.DeepEqual(cs, cs2) && cs.Equivalent(cs2) == nil && cs2.Equivalent(cs) == nil {
if assert.Equal(t, cs, cs2) && assert.NoError(t, cs.Equivalent(cs2)) && assert.NoError(t, cs2.Equivalent(cs)) {
return true // success
}
t.Errorf(`
before: %+#v
after: %+#v`, cs, cs2)
return false
}

Expand All @@ -134,9 +132,7 @@ after: %+#v`, cs, cs2)
}
}

if err := quick.Check(func(cs rndConfChange) bool {
assert.NoError(t, quick.Check(func(cs rndConfChange) bool {
return f(pb.ConfState(cs))
}, &cfg); err != nil {
t.Error(err)
}
}, &cfg))
}
Loading