Skip to content

Commit

Permalink
Merge pull request #17730 from serathius/robustness-no-failpoint
Browse files Browse the repository at this point in the history
Make no failpoint error more readable
  • Loading branch information
serathius authored Apr 8, 2024
2 parents 84e67ff + 3a23994 commit 0be1976
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions tests/robustness/failpoint/failpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions tests/robustness/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0be1976

Please sign in to comment.