Skip to content

Commit 6b563cb

Browse files
committed
robustness: improve error handling for NewTestReport
Signed-off-by: Chun-Hung Tseng <henrytseng@google.com>
1 parent 826d732 commit 6b563cb

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

tests/antithesis/test-template/robustness/traffic/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ func main() {
7676
choice := rand.IntN(len(traffics))
7777
tf := traffics[choice]
7878
lg.Info("Traffic", zap.String("Type", trafficNames[choice]))
79-
r := report.NewTestReport(lg, reportPath, etcdetcdDataPaths, &report.TrafficDetail{ExpectUniqueRevision: tf.ExpectUniqueRevision()})
79+
r, err := report.NewTestReport(lg, reportPath, etcdetcdDataPaths, &report.TrafficDetail{ExpectUniqueRevision: tf.ExpectUniqueRevision()})
80+
if err != nil {
81+
lg.Fatal("Failed to create test report", zap.Error(err))
82+
}
8083
defer func() {
8184
if err = r.SaveEtcdData(); err != nil {
8285
lg.Error("Failed to save traffic generation report", zap.Error(err))

tests/robustness/main_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ func TestRobustnessRegression(t *testing.T) {
8888
}
8989

9090
func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s scenarios.TestScenario, c *e2e.EtcdProcessCluster) {
91-
r := report.NewTestReport(lg, testResultsDirectory(t), report.ServerDataPaths(c), &report.TrafficDetail{ExpectUniqueRevision: s.Traffic.ExpectUniqueRevision()})
91+
r, err := report.NewTestReport(lg, testResultsDirectory(t), report.ServerDataPaths(c), &report.TrafficDetail{ExpectUniqueRevision: s.Traffic.ExpectUniqueRevision()})
92+
require.NoError(t, err)
9293
// t.Failed() returns false during panicking. We need to forcibly
9394
// save data on panicking.
9495
// Refer to: https://github.com/golang/go/issues/49929

tests/robustness/report/report.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ type TestReport struct {
3636
dataSaved bool
3737
}
3838

39-
func NewTestReport(lg *zap.Logger, reportPath string, serverDataPaths map[string]string, traffic *TrafficDetail) *TestReport {
39+
func NewTestReport(lg *zap.Logger, reportPath string, serverDataPaths map[string]string, traffic *TrafficDetail) (*TestReport, error) {
4040
if reportPath == "" {
41-
panic("reportPath is not set")
41+
return nil, fmt.Errorf("reportPath is not set")
4242
}
4343
return &TestReport{
4444
logger: lg,
4545
reportPath: reportPath,
4646
serverDataPaths: serverDataPaths,
4747
traffic: traffic,
48-
}
48+
}, nil
4949
}
5050

5151
func (r *TestReport) SetClientReports(reports []ClientReport) {

0 commit comments

Comments
 (0)