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

fix: use require instead of t.Fatal(err) in tests/integration package #18820

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions tests/integration/clientv3/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"go.etcd.io/etcd/client/pkg/v3/types"
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
)
Expand Down Expand Up @@ -266,9 +268,8 @@ func TestMemberPromote(t *testing.T) {
// (the response has information on peer urls of the existing members in cluster)
learnerMember := clus.MustNewMember(t, memberAddResp)

if err = learnerMember.Launch(); err != nil {
t.Fatal(err)
}
err = learnerMember.Launch()
require.NoError(t, err)

// retry until promote succeed or timeout
timeout := time.After(5 * time.Second)
Expand Down
46 changes: 16 additions & 30 deletions tests/integration/clientv3/concurrency/mutex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,31 @@ import (
"errors"
"testing"

"github.com/stretchr/testify/require"

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
)

func TestMutexLockSessionExpired(t *testing.T) {
cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: exampleEndpoints()})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()

// create two separate sessions for lock competition
s1, err := concurrency.NewSession(cli)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer s1.Close()
m1 := concurrency.NewMutex(s1, "/my-lock/")

s2, err := concurrency.NewSession(cli)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
m2 := concurrency.NewMutex(s2, "/my-lock/")

// acquire lock for s1
if err = m1.Lock(context.TODO()); err != nil {
t.Fatal(err)
}
err = m1.Lock(context.TODO())
require.NoError(t, err)

m2Locked := make(chan struct{})
var err2 error
Expand All @@ -62,27 +57,20 @@ func TestMutexLockSessionExpired(t *testing.T) {

// revoke the session of m2 before unlock m1
err = s2.Close()
if err != nil {
t.Fatal(err)
}
if err := m1.Unlock(context.TODO()); err != nil {
t.Fatal(err)
}
require.NoError(t, err)
err = m1.Unlock(context.TODO())
require.NoError(t, err)

<-m2Locked
}

func TestMutexUnlock(t *testing.T) {
cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: exampleEndpoints()})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()

s1, err := concurrency.NewSession(cli)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer s1.Close()

m1 := concurrency.NewMutex(s1, "/my-lock/")
Expand All @@ -94,13 +82,11 @@ func TestMutexUnlock(t *testing.T) {
t.Fatal(err)
}

if err = m1.Lock(context.TODO()); err != nil {
t.Fatal(err)
}
err = m1.Lock(context.TODO())
require.NoError(t, err)

if err = m1.Unlock(context.TODO()); err != nil {
t.Fatal(err)
}
err = m1.Unlock(context.TODO())
require.NoError(t, err)

err = m1.Unlock(context.TODO())
if err == nil {
Expand Down
33 changes: 9 additions & 24 deletions tests/integration/clientv3/concurrency/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

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

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
Expand All @@ -28,18 +29,12 @@ import (

func TestSessionOptions(t *testing.T) {
cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: exampleEndpoints()})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()
lease, err := cli.Grant(context.Background(), 100)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
s, err := concurrency.NewSession(cli, concurrency.WithLease(lease.ID))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer s.Close()
assert.Equal(t, s.Lease(), lease.ID)

Expand All @@ -52,16 +47,12 @@ func TestSessionOptions(t *testing.T) {
}
func TestSessionTTLOptions(t *testing.T) {
cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: exampleEndpoints()})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()

var setTTL = 90
s, err := concurrency.NewSession(cli, concurrency.WithTTL(setTTL))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer s.Close()

leaseID := s.Lease()
Expand All @@ -83,18 +74,12 @@ func TestSessionTTLOptions(t *testing.T) {

func TestSessionCtx(t *testing.T) {
cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: exampleEndpoints()})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()
lease, err := cli.Grant(context.Background(), 100)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
s, err := concurrency.NewSession(cli, concurrency.WithLease(lease.ID))
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer s.Close()
assert.Equal(t, s.Lease(), lease.ID)

Expand Down
28 changes: 10 additions & 18 deletions tests/integration/clientv3/connectivity/black_hole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
"google.golang.org/grpc"

"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
Expand Down Expand Up @@ -62,9 +63,7 @@ func TestBalancerUnderBlackholeKeepAliveWatch(t *testing.T) {
timeout := pingInterval + integration2.RequestWaitTimeout

cli, err := integration2.NewClient(t, ccfg)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()

wch := cli.Watch(context.Background(), "foo", clientv3.WithCreatedNotify())
Expand All @@ -80,9 +79,8 @@ func TestBalancerUnderBlackholeKeepAliveWatch(t *testing.T) {

clus.Members[0].Bridge().Blackhole()

if _, err = clus.Client(1).Put(context.TODO(), "foo", "bar"); err != nil {
t.Fatal(err)
}
_, err = clus.Client(1).Put(context.TODO(), "foo", "bar")
require.NoError(t, err)
select {
case <-wch:
case <-time.After(timeout):
Expand All @@ -97,12 +95,10 @@ func TestBalancerUnderBlackholeKeepAliveWatch(t *testing.T) {
clus.Members[1].Bridge().Blackhole()

// make sure client[0] can connect to eps[0] after remove the blackhole.
if _, err = clus.Client(0).Get(context.TODO(), "foo"); err != nil {
t.Fatal(err)
}
if _, err = clus.Client(0).Put(context.TODO(), "foo", "bar1"); err != nil {
t.Fatal(err)
}
_, err = clus.Client(0).Get(context.TODO(), "foo")
require.NoError(t, err)
_, err = clus.Client(0).Put(context.TODO(), "foo", "bar1")
require.NoError(t, err)

select {
case <-wch:
Expand Down Expand Up @@ -183,9 +179,7 @@ func testBalancerUnderBlackholeNoKeepAlive(t *testing.T, op func(*clientv3.Clien
DialOptions: []grpc.DialOption{grpc.WithBlock()},
}
cli, err := integration2.NewClient(t, ccfg)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()

// wait for eps[0] to be pinned
Expand Down Expand Up @@ -214,7 +208,5 @@ func testBalancerUnderBlackholeNoKeepAlive(t *testing.T, op func(*clientv3.Clien
t.Errorf("#%d: failed with error %v", i, err)
}
}
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
}
32 changes: 11 additions & 21 deletions tests/integration/clientv3/connectivity/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
"google.golang.org/grpc"

pb "go.etcd.io/etcd/api/v3/etcdserverpb"
Expand Down Expand Up @@ -54,9 +55,7 @@ func TestDialTLSExpired(t *testing.T) {
defer clus.Terminate(t)

tls, err := testTLSInfoExpired.ClientConfig()
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
// expect remote errors "tls: bad certificate"
_, err = integration2.NewClient(t, clientv3.Config{
Endpoints: []string{clus.Members[0].GRPCURL},
Expand Down Expand Up @@ -120,9 +119,7 @@ func testDialSetEndpoints(t *testing.T, setBefore bool) {
DialOptions: []grpc.DialOption{grpc.WithBlock()},
}
cli, err := integration2.NewClient(t, cfg)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer cli.Close()

if setBefore {
Expand All @@ -137,9 +134,8 @@ func testDialSetEndpoints(t *testing.T, setBefore bool) {
}
time.Sleep(time.Second * 2)
ctx, cancel := context.WithTimeout(context.Background(), integration2.RequestWaitTimeout)
if _, err = cli.Get(ctx, "foo", clientv3.WithSerializable()); err != nil {
t.Fatal(err)
}
_, err = cli.Get(ctx, "foo", clientv3.WithSerializable())
require.NoError(t, err)
cancel()
}

Expand All @@ -160,9 +156,8 @@ func TestSwitchSetEndpoints(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if _, err := cli.Get(ctx, "foo"); err != nil {
t.Fatal(err)
}
_, err := cli.Get(ctx, "foo")
require.NoError(t, err)
}

func TestRejectOldCluster(t *testing.T) {
Expand All @@ -178,9 +173,7 @@ func TestRejectOldCluster(t *testing.T) {
RejectOldCluster: true,
}
cli, err := integration2.NewClient(t, cfg)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
cli.Close()
}

Expand All @@ -192,19 +185,16 @@ func TestDialForeignEndpoint(t *testing.T) {
defer clus.Terminate(t)

conn, err := clus.Client(0).Dial(clus.Client(1).Endpoints()[0])
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer conn.Close()

// grpc can return a lazy connection that's not connected yet; confirm
// that it can communicate with the cluster.
kvc := clientv3.NewKVFromKVClient(pb.NewKVClient(conn), clus.Client(0))
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
defer cancel()
if _, gerr := kvc.Get(ctx, "abc"); gerr != nil {
t.Fatal(err)
}
_, gerr := kvc.Get(ctx, "abc")
require.NoError(t, gerr)
}

// TestSetEndpointAndPut checks that a Put following a SetEndpoints
Expand Down
Loading
Loading