Skip to content

Commit

Permalink
Move service status check just after data collection. (#1551)
Browse files Browse the repository at this point in the history
* Move service status check just after data collection.

* Rename specific error for clarity

* Use typed error to avoid early exit
  • Loading branch information
marc-gr authored Nov 9, 2023
1 parent 20c4811 commit 53c2f4f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
logger.Debug("checking for expected data in data stream...")
var hits *hits
oldHits := 0
passed, err := waitUntilTrue(func() (bool, error) {
passed, waitErr := waitUntilTrue(func() (bool, error) {
if signal.SIGINT() {
return true, errors.New("SIGINT: cancel waiting for policy assigned")
}
Expand All @@ -662,8 +662,18 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
return hits.size() > 0, err
}, waitForDataTimeout)

if err != nil {
return result.WithError(err)
if config.Service != "" && !config.IgnoreServiceError {
exited, code, err := service.ExitCode(config.Service)
if err != nil && !errors.Is(err, servicedeployer.ErrNotSupported) {
return result.WithError(err)
}
if exited && code > 0 {
return result.WithError(testrunner.ErrTestCaseFailed{Reason: fmt.Sprintf("the test service %s unexpectedly exited with code %d", config.Service, code)})
}
}

if waitErr != nil {
return result.WithError(waitErr)
}

if !passed {
Expand Down Expand Up @@ -753,16 +763,6 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
return result.WithError(err)
}

if config.Service != "" && !config.IgnoreServiceError {
exited, code, err := service.ExitCode(config.Service)
if err != nil && !errors.Is(err, servicedeployer.ErrNotSupported) {
return result.WithError(err)
}
if exited && code > 0 {
result.FailureMsg = fmt.Sprintf("the test service %s unexpectedly exited with code %d", config.Service, code)
}
}

return result.WithSuccess()
}

Expand Down

0 comments on commit 53c2f4f

Please sign in to comment.