Skip to content

Commit

Permalink
Fix exit error status
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam committed Oct 1, 2024
1 parent 998d207 commit c977eaa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
33 changes: 0 additions & 33 deletions pkg/cmd/cmdrun/util.go
Original file line number Diff line number Diff line change
@@ -1,34 +1 @@
package cmdrun

import (
"fmt"
"time"

"github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
)

func runSpec(spec *extensiontests.ExtensionTestSpec) *extensiontests.ExtensionTestResult {
startTime := time.Now()
res := spec.Run()
duration := time.Since(startTime)
endTime := startTime.Add(duration)
if res == nil {
// this shouldn't happen
panic(fmt.Sprintf("test produced no result: %s", spec.Name))
}

res.Lifecycle = spec.Lifecycle

// If the runner doesn't populate this info, we should set it
if res.StartTime == nil {
res.StartTime = &startTime
}
if res.EndTime == nil {
res.EndTime = &endTime
}
if res.Duration == 0 {
res.Duration = duration.Milliseconds()
}

return res
}
29 changes: 28 additions & 1 deletion pkg/extension/extensiontests/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extensiontests

import (
"fmt"
"time"

"github.com/google/cel-go/cel"
"github.com/google/cel-go/checker/decls"
Expand All @@ -20,7 +21,7 @@ func (specs ExtensionTestSpecs) Run(w *ResultWriter) error {
var results ExtensionTestResults

specs.Walk(func(spec *ExtensionTestSpec) {
res := spec.Run()
res := runSpec(spec)
w.Write(res)
results = append(results, res)
})
Expand Down Expand Up @@ -135,3 +136,29 @@ func (specs ExtensionTestSpecs) UnsetTag(key string) ExtensionTestSpecs {

return specs
}

func runSpec(spec *ExtensionTestSpec) *ExtensionTestResult {
startTime := time.Now()
res := spec.Run()
duration := time.Since(startTime)
endTime := startTime.Add(duration)
if res == nil {
// this shouldn't happen
panic(fmt.Sprintf("test produced no result: %s", spec.Name))
}

res.Lifecycle = spec.Lifecycle

// If the runner doesn't populate this info, we should set it
if res.StartTime == nil {
res.StartTime = &startTime
}
if res.EndTime == nil {
res.EndTime = &endTime
}
if res.Duration == 0 {
res.Duration = duration.Milliseconds()
}

return res
}
2 changes: 1 addition & 1 deletion test/framework/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _ = Describe("[sig-testing] example-tests run-suite", Label("framework"), fu
cmd := exec.Command("./example-tests", "run-suite", "example/fast")

// Capture both stdout and stderr
output, cmdErr = cmd.CombinedOutput()
output, cmdErr = cmd.Output()

// Expect command to exit with a non-zero status (exit code 1 for failed tests)
var exitErr *exec.ExitError
Expand Down

0 comments on commit c977eaa

Please sign in to comment.