From 3a23994fbfcbe4935a9bda947358c50b61b7e395 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Sun, 7 Apr 2024 15:13:56 +0200 Subject: [PATCH] Make no failpoint error more readable Signed-off-by: Marek Siarkowicz --- tests/robustness/failpoint/failpoint.go | 7 +++---- tests/robustness/main_test.go | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/robustness/failpoint/failpoint.go b/tests/robustness/failpoint/failpoint.go index 12a72b69d..d52b64f4a 100644 --- a/tests/robustness/failpoint/failpoint.go +++ b/tests/robustness/failpoint/failpoint.go @@ -54,7 +54,7 @@ var ( } ) -func PickRandom(t *testing.T, clus *e2e.EtcdProcessCluster) Failpoint { +func PickRandom(clus *e2e.EtcdProcessCluster) (Failpoint, error) { availableFailpoints := make([]Failpoint, 0, len(allFailpoints)) for _, failpoint := range allFailpoints { err := Validate(clus, failpoint) @@ -64,10 +64,9 @@ func PickRandom(t *testing.T, clus *e2e.EtcdProcessCluster) Failpoint { availableFailpoints = append(availableFailpoints, failpoint) } if len(availableFailpoints) == 0 { - t.Errorf("No available failpoints") - return nil + return nil, fmt.Errorf("no available failpoints") } - return availableFailpoints[rand.Int()%len(availableFailpoints)] + return availableFailpoints[rand.Int()%len(availableFailpoints)], nil } func Validate(clus *e2e.EtcdProcessCluster, failpoint Failpoint) error { diff --git a/tests/robustness/main_test.go b/tests/robustness/main_test.go index ccd853b7c..6572b2e1a 100644 --- a/tests/robustness/main_test.go +++ b/tests/robustness/main_test.go @@ -73,13 +73,15 @@ func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testSce defer report.Cluster.Close() if s.failpoint == nil { - s.failpoint = failpoint.PickRandom(t, report.Cluster) - } else { - err = failpoint.Validate(report.Cluster, s.failpoint) + s.failpoint, err = failpoint.PickRandom(report.Cluster) if err != nil { t.Fatal(err) } } + err = failpoint.Validate(report.Cluster, s.failpoint) + if err != nil { + t.Fatal(err) + } // t.Failed() returns false during panicking. We need to forcibly // save data on panicking.