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
33 changes: 12 additions & 21 deletions tests/integration/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ func TestIssue2681(t *testing.T) {
c := integration.NewCluster(t, &integration.ClusterConfig{Size: 5, DisableStrictReconfigCheck: true})
defer c.Terminate(t)

if err := c.RemoveMember(t, c.Members[0].Client, uint64(c.Members[4].Server.MemberID())); err != nil {
t.Fatal(err)
}
err := c.RemoveMember(t, c.Members[0].Client, uint64(c.Members[4].Server.MemberID()))
require.NoError(t, err)
c.WaitMembersForLeader(t, c.Members)

c.AddMember(t)
Expand All @@ -234,9 +233,8 @@ func testIssue2746(t *testing.T, members int) {
clusterMustProgress(t, c.Members)
}

if err := c.RemoveMember(t, c.Members[0].Client, uint64(c.Members[members-1].Server.MemberID())); err != nil {
t.Fatal(err)
}
err := c.RemoveMember(t, c.Members[0].Client, uint64(c.Members[members-1].Server.MemberID()))
require.NoError(t, err)
c.WaitMembersForLeader(t, c.Members)

c.AddMember(t)
Expand Down Expand Up @@ -312,9 +310,8 @@ func TestIssue3699(t *testing.T) {
t.Logf("Restarting member '0'...")
// bring back node a
// node a will remain useless as long as d is the leader.
if err := c.Members[0].Restart(t); err != nil {
t.Fatal(err)
}
err := c.Members[0].Restart(t)
require.NoError(t, err)
t.Logf("Restarted member '0'.")

select {
Expand Down Expand Up @@ -530,19 +527,16 @@ func TestConcurrentRemoveMember(t *testing.T) {
defer c.Terminate(t)

addResp, err := c.Members[0].Client.MemberAddAsLearner(context.Background(), []string{"http://localhost:123"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
removeID := addResp.Member.ID
done := make(chan struct{})
go func() {
time.Sleep(time.Second / 2)
c.Members[0].Client.MemberRemove(context.Background(), removeID)
close(done)
}()
if _, err := c.Members[0].Client.MemberRemove(context.Background(), removeID); err != nil {
t.Fatal(err)
}
_, err = c.Members[0].Client.MemberRemove(context.Background(), removeID)
require.NoError(t, err)
<-done
}

Expand All @@ -552,18 +546,15 @@ func TestConcurrentMoveLeader(t *testing.T) {
defer c.Terminate(t)

addResp, err := c.Members[0].Client.MemberAddAsLearner(context.Background(), []string{"http://localhost:123"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
removeID := addResp.Member.ID
done := make(chan struct{})
go func() {
time.Sleep(time.Second / 2)
c.Members[0].Client.MoveLeader(context.Background(), removeID)
close(done)
}()
if _, err := c.Members[0].Client.MemberRemove(context.Background(), removeID); err != nil {
t.Fatal(err)
}
_, err = c.Members[0].Client.MemberRemove(context.Background(), removeID)
require.NoError(t, err)
<-done
}
13 changes: 4 additions & 9 deletions tests/integration/grpc_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"

clientv3 "go.etcd.io/etcd/client/v3"
Expand Down Expand Up @@ -105,9 +106,7 @@ func TestAuthority(t *testing.T) {
putRequestMethod := "/etcdserverpb.KV/Put"
for i := 0; i < 100; i++ {
_, err := kv.Put(context.TODO(), "foo", "bar")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
}

assertAuthority(t, tc.expectAuthorityPattern, clus, putRequestMethod)
Expand All @@ -121,9 +120,7 @@ func setupTLS(t *testing.T, useTLS bool, cfg integration.ClusterConfig) (integra
if useTLS {
cfg.ClientTLS = &integration.TestTLSInfo
tlsConfig, err := integration.TestTLSInfo.ClientConfig()
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
return cfg, tlsConfig
}
return cfg, nil
Expand All @@ -138,9 +135,7 @@ func setupClient(t *testing.T, endpointPattern string, clus *integration.Cluster
DialOptions: []grpc.DialOption{grpc.WithBlock()},
TLS: tlsConfig,
})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
return kv
}

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/hashkv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/etcdserver"
"go.etcd.io/etcd/server/v3/storage/mvcc/testutil"
Expand All @@ -36,9 +38,7 @@ func TestCompactionHash(t *testing.T) {
defer clus.Terminate(t)

cc, err := clus.ClusterClient(t)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
client := &http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ func TestRestartMember(t *testing.T) {
c.WaitMembersForLeader(t, membs)
clusterMustProgress(t, membs)
err := c.Members[i].Restart(t)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
}
c.WaitMembersForLeader(t, c.Members)
clusterMustProgress(t, c.Members)
Expand Down
65 changes: 17 additions & 48 deletions tests/integration/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ func TestMetricDbSizeBoot(t *testing.T) {
defer clus.Terminate(t)

v, err := clus.Members[0].Metric("etcd_debugging_mvcc_db_total_size_in_bytes")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

if v == "0" {
t.Fatalf("expected non-zero, got %q", v)
Expand Down Expand Up @@ -74,40 +72,29 @@ func testMetricDbSizeDefrag(t *testing.T, name string) {

expected := numPuts * len(putreq.Value)
beforeDefrag, err := clus.Members[0].Metric(name + "_mvcc_db_total_size_in_bytes")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
bv, err := strconv.Atoi(beforeDefrag)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if bv < expected {
t.Fatalf("expected db size greater than %d, got %d", expected, bv)
}
beforeDefragInUse, err := clus.Members[0].Metric("etcd_mvcc_db_total_size_in_use_in_bytes")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
biu, err := strconv.Atoi(beforeDefragInUse)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if biu < expected {
t.Fatalf("expected db size in use is greater than %d, got %d", expected, biu)
}

// clear out historical keys, in use bytes should free pages
creq := &pb.CompactionRequest{Revision: int64(numPuts), Physical: true}
if _, kerr := kvc.Compact(context.TODO(), creq); kerr != nil {
t.Fatal(kerr)
}
_, kerr := kvc.Compact(context.TODO(), creq)
require.NoError(t, kerr)

validateAfterCompactionInUse := func() error {
// Put to move PendingPages to FreePages
_, verr := kvc.Put(context.TODO(), putreq)
if verr != nil {
t.Fatal(verr)
}
require.NoError(t, verr)
time.Sleep(500 * time.Millisecond)

afterCompactionInUse, verr := clus.Members[0].Metric("etcd_mvcc_db_total_size_in_use_in_bytes")
Expand Down Expand Up @@ -142,25 +129,17 @@ func testMetricDbSizeDefrag(t *testing.T, name string) {
mc.Defragment(context.TODO(), &pb.DefragmentRequest{})

afterDefrag, err := clus.Members[0].Metric(name + "_mvcc_db_total_size_in_bytes")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
av, err := strconv.Atoi(afterDefrag)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if bv <= av {
t.Fatalf("expected less than %d, got %d after defrag", bv, av)
}

afterDefragInUse, err := clus.Members[0].Metric("etcd_mvcc_db_total_size_in_use_in_bytes")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
adiu, err := strconv.Atoi(afterDefragInUse)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if adiu > av {
t.Fatalf("db size in use (%d) is expected less than db size (%d) after defrag", adiu, av)
}
Expand All @@ -172,13 +151,9 @@ func TestMetricQuotaBackendBytes(t *testing.T) {
defer clus.Terminate(t)

qs, err := clus.Members[0].Metric("etcd_server_quota_backend_bytes")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
qv, err := strconv.ParseFloat(qs, 64)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if int64(qv) != storage.DefaultQuotaBytes {
t.Fatalf("expected %d, got %f", storage.DefaultQuotaBytes, qv)
}
Expand All @@ -190,9 +165,7 @@ func TestMetricsHealth(t *testing.T) {
defer clus.Terminate(t)

tr, err := transport.NewTransport(transport.TLSInfo{}, 5*time.Second)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
u := clus.Members[0].ClientURLs[0]
u.Path = "/health"
resp, err := tr.RoundTrip(&http.Request{
Expand All @@ -201,14 +174,10 @@ func TestMetricsHealth(t *testing.T) {
URL: &u,
})
resp.Body.Close()
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

hv, err := clus.Members[0].Metric("etcd_server_health_failures")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
if hv != "0" {
t.Fatalf("expected '0' from etcd_server_health_failures, got %q", hv)
}
Expand Down
16 changes: 6 additions & 10 deletions tests/integration/revision_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/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/status"

"go.etcd.io/etcd/tests/v3/framework/integration"
Expand Down Expand Up @@ -95,17 +97,15 @@ func testRevisionMonotonicWithFailures(t *testing.T, testDuration time.Duration,
wg.Add(1)
go func() {
defer wg.Done()
getWorker(ctx, t, clus)
getWorker(ctx, t, clus) //nolint:testifylint
}()
}

injectFailures(clus)
wg.Wait()
kv := clus.Client(0)
resp, err := kv.Get(context.Background(), "foo")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
t.Logf("Revision %d", resp.Header.Revision)
}

Expand All @@ -116,9 +116,7 @@ func putWorker(ctx context.Context, t *testing.T, clus *integration.Cluster) {
if errors.Is(err, context.DeadlineExceeded) {
return
}
if silenceConnectionErrors(err) != nil {
t.Fatal(err)
}
assert.NoError(t, silenceConnectionErrors(err))
}
}

Expand All @@ -130,9 +128,7 @@ func getWorker(ctx context.Context, t *testing.T, clus *integration.Cluster) {
if errors.Is(err, context.DeadlineExceeded) {
return
}
if silenceConnectionErrors(err) != nil {
t.Fatal(err)
}
require.NoError(t, silenceConnectionErrors(err))
if resp == nil {
continue
}
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ func TestTracing(t *testing.T) {
"Wal creation tests are depending on embedded etcd server so are integration-level tests.")
// set up trace collector
listener, err := net.Listen("tcp", "localhost:")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

traceFound := make(chan struct{})
defer close(traceFound)
Expand All @@ -64,9 +62,7 @@ func TestTracing(t *testing.T) {

// start an etcd instance with tracing enabled
etcdSrv, err := embed.StartEtcd(cfg)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer etcdSrv.Close()

select {
Expand Down
13 changes: 4 additions & 9 deletions tests/integration/utl_wal_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/coreos/go-semver/semver"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"go.etcd.io/etcd/client/pkg/v3/testutil"
Expand All @@ -37,9 +38,7 @@ func TestEtcdVersionFromWAL(t *testing.T) {
"Wal creation tests are depending on embedded etcd server so are integration-level tests.")
cfg := integration.NewEmbedConfig(t, "default")
srv, err := embed.StartEtcd(cfg)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
select {
case <-srv.Server.ReadyNotify():
case <-time.After(3 * time.Second):
Expand Down Expand Up @@ -76,15 +75,11 @@ func TestEtcdVersionFromWAL(t *testing.T) {
srv.Close()

w, err := wal.Open(zap.NewNop(), cfg.Dir+"/member/wal", walpb.Snapshot{})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer w.Close()

walVersion, err := wal.ReadWALVersion(w)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
assert.Equal(t, &semver.Version{Major: 3, Minor: 6}, walVersion.MinimalEtcdVersion())
}

Expand Down
Loading
Loading