From 40bff3ee20fabc19fb22396edd5e1e340a2c3d43 Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Thu, 9 Nov 2023 14:35:56 +0100 Subject: [PATCH 1/3] Move service status check just after data collection. --- internal/testrunner/runners/system/runner.go | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/testrunner/runners/system/runner.go b/internal/testrunner/runners/system/runner.go index d5a5696724..f1c63f3498 100644 --- a/internal/testrunner/runners/system/runner.go +++ b/internal/testrunner/runners/system/runner.go @@ -662,6 +662,17 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext return hits.size() > 0, err }, waitForDataTimeout) + 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.WithError(fmt.Errorf("%s", result.FailureMsg)) + } + } + if err != nil { return result.WithError(err) } @@ -753,16 +764,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() } From f7ad10703f239e3f1cbf7e1ab5045a7688b58bb4 Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Thu, 9 Nov 2023 14:50:35 +0100 Subject: [PATCH 2/3] Rename specific error for clarity --- internal/testrunner/runners/system/runner.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/testrunner/runners/system/runner.go b/internal/testrunner/runners/system/runner.go index f1c63f3498..6b8d395e89 100644 --- a/internal/testrunner/runners/system/runner.go +++ b/internal/testrunner/runners/system/runner.go @@ -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") } @@ -673,8 +673,8 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext } } - if err != nil { - return result.WithError(err) + if waitErr != nil { + return result.WithError(waitErr) } if !passed { From 83242b97983fa48b81c24e1f1da97bf2d5b25bed Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Thu, 9 Nov 2023 17:04:52 +0100 Subject: [PATCH 3/3] Use typed error to avoid early exit --- internal/testrunner/runners/system/runner.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/testrunner/runners/system/runner.go b/internal/testrunner/runners/system/runner.go index 6b8d395e89..0e25fc39ae 100644 --- a/internal/testrunner/runners/system/runner.go +++ b/internal/testrunner/runners/system/runner.go @@ -668,8 +668,7 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext 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.WithError(fmt.Errorf("%s", result.FailureMsg)) + return result.WithError(testrunner.ErrTestCaseFailed{Reason: fmt.Sprintf("the test service %s unexpectedly exited with code %d", config.Service, code)}) } }