diff --git a/tests/robustness/client/watch.go b/tests/robustness/client/watch.go index a22afa22193..ca7ce9f9f9a 100644 --- a/tests/robustness/client/watch.go +++ b/tests/robustness/client/watch.go @@ -20,6 +20,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/tests/v3/framework/e2e" "go.etcd.io/etcd/tests/v3/robustness/identity" "go.etcd.io/etcd/tests/v3/robustness/report" @@ -32,9 +34,7 @@ func CollectClusterWatchEvents(ctx context.Context, t *testing.T, clus *e2e.Etcd memberMaxRevisionChans := make([]chan int64, len(clus.Procs)) for i, member := range clus.Procs { c, err := NewRecordingClient(member.EndpointsGRPC(), ids, baseTime) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) memberMaxRevisionChan := make(chan int64, 1) memberMaxRevisionChans[i] = memberMaxRevisionChan wg.Add(1) diff --git a/tests/robustness/failpoint/cluster.go b/tests/robustness/failpoint/cluster.go index 63aed056f2e..f756e814b42 100644 --- a/tests/robustness/failpoint/cluster.go +++ b/tests/robustness/failpoint/cluster.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "go.uber.org/zap" clientv3 "go.etcd.io/etcd/client/v3" @@ -56,9 +57,8 @@ func (f memberReplace) Inject(ctx context.Context, t *testing.T, lg *zap.Logger, if err != nil { return nil, err } - if !found { - t.Fatal("Member not found") - } + require.Truef(t, found, "Member not found") + // Need to wait health interval for cluster to accept member changes time.Sleep(etcdserver.HealthInterval) lg.Info("Removing member", zap.String("member", member.Config().Name)) @@ -70,9 +70,7 @@ func (f memberReplace) Inject(ctx context.Context, t *testing.T, lg *zap.Logger, if err != nil { return nil, err } - if found { - t.Fatal("Expected member to be removed") - } + require.Falsef(t, found, "Expected member to be removed") for member.IsRunning() { err = member.Kill() diff --git a/tests/robustness/report/client.go b/tests/robustness/report/client.go index 9a4431f7585..b2ae5a6b261 100644 --- a/tests/robustness/report/client.go +++ b/tests/robustness/report/client.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/anishathalye/porcupine" + "github.com/stretchr/testify/require" "go.uber.org/zap" "go.etcd.io/etcd/tests/v3/robustness/model" @@ -53,9 +54,7 @@ func persistClientReports(t *testing.T, lg *zap.Logger, path string, reports []C for _, r := range reports { clientDir := filepath.Join(path, fmt.Sprintf("client-%d", r.ClientID)) err := os.MkdirAll(clientDir, 0700) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if len(r.Watch) != 0 { persistWatchOperations(t, lg, filepath.Join(clientDir, "watch.json"), r.Watch) } else { diff --git a/tests/robustness/report/report.go b/tests/robustness/report/report.go index cd45f1d1bcb..162d2dcb4f8 100644 --- a/tests/robustness/report/report.go +++ b/tests/robustness/report/report.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "go.uber.org/zap" "go.etcd.io/etcd/tests/v3/framework/e2e" @@ -45,17 +46,11 @@ func testResultsDirectory(t *testing.T) string { } path, err := filepath.Abs(filepath.Join( resultsDirectory, strings.ReplaceAll(t.Name(), "/", "_"), fmt.Sprintf("%v", time.Now().UnixNano()))) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) err = os.RemoveAll(path) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) err = os.MkdirAll(path, 0700) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return path } @@ -84,9 +79,7 @@ func (r *TestReport) Report(t *testing.T, force bool) { func persistMemberDataDir(t *testing.T, lg *zap.Logger, member e2e.EtcdProcess, path string) { lg.Info("Saving member data dir", zap.String("member", member.Config().Name), zap.String("path", path)) err := os.Rename(memberDataDir(member), path) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } func memberDataDir(member e2e.EtcdProcess) string { diff --git a/tests/robustness/scenarios/scenarios.go b/tests/robustness/scenarios/scenarios.go index c6bf56a1c1a..6034ee9b312 100644 --- a/tests/robustness/scenarios/scenarios.go +++ b/tests/robustness/scenarios/scenarios.go @@ -19,6 +19,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/api/v3/version" "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/tests/v3/framework/e2e" @@ -153,9 +155,7 @@ func Exploratory(_ *testing.T) []TestScenario { func Regression(t *testing.T) []TestScenario { v, err := e2e.GetVersionFromBinary(e2e.BinPath.Etcd) - if err != nil { - t.Fatalf("Failed checking etcd version binary, binary: %q, err: %v", e2e.BinPath.Etcd, err) - } + require.NoErrorf(t, err, "Failed checking etcd version binary, binary: %q", e2e.BinPath.Etcd) scenarios := []TestScenario{} scenarios = append(scenarios, TestScenario{ diff --git a/tests/robustness/traffic/traffic.go b/tests/robustness/traffic/traffic.go index 77292e6c95e..09580ec8187 100644 --- a/tests/robustness/traffic/traffic.go +++ b/tests/robustness/traffic/traffic.go @@ -20,6 +20,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "go.uber.org/zap" "golang.org/x/time/rate" @@ -62,15 +63,11 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2 limiter := rate.NewLimiter(rate.Limit(profile.MaximalQPS), 200) cc, err := client.NewRecordingClient(endpoints, ids, baseTime) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer cc.Close() // Ensure that first operation succeeds _, err = cc.Put(ctx, "start", "true") - if err != nil { - t.Fatalf("First operation failed, validation requires first operation to succeed, err: %s", err) - } + require.NoErrorf(t, err, "First operation failed, validation requires first operation to succeed") wg := sync.WaitGroup{} nonUniqueWriteLimiter := NewConcurrencyLimiter(profile.MaxNonUniqueRequestConcurrency) finish := make(chan struct{}) @@ -79,9 +76,7 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2 for i := 0; i < profile.ClientCount; i++ { wg.Add(1) c, nerr := client.NewRecordingClient([]string{endpoints[i%len(endpoints)]}, ids, baseTime) - if nerr != nil { - t.Fatal(nerr) - } + require.NoError(t, nerr) go func(c *client.RecordingClient) { defer wg.Done() defer c.Close() @@ -111,9 +106,7 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2 var fr *report.FailpointInjection select { case frp, ok := <-failpointInjected: - if !ok { - t.Fatalf("Failed to collect failpoint report") - } + require.Truef(t, ok, "Failed to collect failpoint report") fr = &frp case <-ctx.Done(): t.Fatalf("Traffic finished before failure was injected: %s", ctx.Err()) @@ -126,9 +119,7 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2 time.Sleep(time.Second) // Ensure that last operation succeeds _, err = cc.Put(ctx, "tombstone", "true") - if err != nil { - t.Fatalf("Last operation failed, validation requires last operation to succeed, err: %s", err) - } + require.NoErrorf(t, err, "Last operation failed, validation requires last operation to succeed") reports = append(reports, cc.Report()) totalStats := calculateStats(reports, startTime, endTime) diff --git a/tests/robustness/validate/validate.go b/tests/robustness/validate/validate.go index d5422a52eed..e119ea4c574 100644 --- a/tests/robustness/validate/validate.go +++ b/tests/robustness/validate/validate.go @@ -21,6 +21,7 @@ import ( "time" "github.com/anishathalye/porcupine" + "github.com/stretchr/testify/require" "go.uber.org/zap" "go.etcd.io/etcd/tests/v3/robustness/model" @@ -30,9 +31,7 @@ import ( // ValidateAndReturnVisualize returns visualize as porcupine.linearizationInfo used to generate visualization is private. func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, reports []report.ClientReport, persistedRequests []model.EtcdRequest, timeout time.Duration) (visualize func(basepath string) error) { err := checkValidationAssumptions(reports, persistedRequests) - if err != nil { - t.Fatalf("Broken validation assumptions: %s", err) - } + require.NoErrorf(t, err, "Broken validation assumptions") linearizableOperations := patchLinearizableOperations(reports, persistedRequests) serializableOperations := filterSerializableOperations(reports)