Skip to content

Commit 7546004

Browse files
committed
mixedversion: add RunE method to Test
This patch adds a `RunE` method to `Test`. Unlike the existing `Run` function, it will not immediately fatal the test if an error is encountered and will instead return the error along with the test plan so that callers may decide how to handle the error. Release note: None
1 parent a9fa839 commit 7546004

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

pkg/cmd/roachtest/roachtestutil/mixedversion/mixedversion.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,21 +834,29 @@ func (t *Test) Workload(
834834
return t.BackgroundCommand(fmt.Sprintf("%s workload", name), node, runCmd)
835835
}
836836

837-
// Run runs the mixed-version test. It should be called once all
837+
// Run is like RunE, except it fatals the test if any error occurs.
838+
func (t *Test) Run() {
839+
_, err := t.RunE()
840+
if err != nil {
841+
t.rt.Fatal(err)
842+
}
843+
}
844+
845+
// RunE runs the mixed-version test. It should be called once all
838846
// startup, mixed-version, and after-test hooks have been declared. A
839847
// test plan will be generated (and logged), and the test will be
840-
// carried out.
841-
func (t *Test) Run() {
848+
// carried out. A non-nil plan will be returned unless planning fails.
849+
func (t *Test) RunE() (*TestPlan, error) {
842850
plan, err := t.plan()
843851
if err != nil {
844-
t.rt.Fatal(err)
852+
return nil, err
845853
}
846854

847855
t.logger.Printf("mixed-version test:\n%s", plan.PrettyPrint())
848856

849857
if override := os.Getenv(dryRunEnv); override != "" {
850858
t.logger.Printf("skipping test run in dry-run mode")
851-
return
859+
return plan, nil
852860
}
853861

854862
// Mark the deployment mode and versions, so they show up in the github issue. This makes
@@ -857,8 +865,10 @@ func (t *Test) Run() {
857865
t.rt.AddParam("mvtVersions", formatVersions(plan.Versions()))
858866

859867
if err := t.run(plan); err != nil {
860-
t.rt.Fatal(err)
868+
return plan, err
861869
}
870+
871+
return plan, nil
862872
}
863873

864874
func (t *Test) run(plan *TestPlan) error {

0 commit comments

Comments
 (0)