From d50070ae412d07e2684c1d107b43e1bd01c6408e Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Fri, 4 Oct 2024 11:06:01 +0200 Subject: [PATCH] internal/civisibility: fixes the test parent status when the auto-retry feature ended up with a failed test and then a successful test. (#2910) --- .../integrations/gotesting/instrumentation.go | 6 +++++- .../integrations/gotesting/testing_test.go | 17 +++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/internal/civisibility/integrations/gotesting/instrumentation.go b/internal/civisibility/integrations/gotesting/instrumentation.go index af40c23570..82aac9868b 100644 --- a/internal/civisibility/integrations/gotesting/instrumentation.go +++ b/internal/civisibility/integrations/gotesting/instrumentation.go @@ -571,7 +571,11 @@ func applyAdditionalFeaturesToTestFunc(f func(*testing.T)) func(*testing.T) { tCommonPrivates := getTestPrivateFields(t) tCommonPrivates.SetFailed(ptrToLocalT.Failed()) tCommonPrivates.SetSkipped(ptrToLocalT.Skipped()) - tParentCommonPrivates.SetFailed(ptrToLocalT.Failed()) + + // Only change the parent status to failing if the current test failed + if ptrToLocalT.Failed() { + tParentCommonPrivates.SetFailed(ptrToLocalT.Failed()) + } break } } diff --git a/internal/civisibility/integrations/gotesting/testing_test.go b/internal/civisibility/integrations/gotesting/testing_test.go index 0dcbdb559d..2f41387280 100644 --- a/internal/civisibility/integrations/gotesting/testing_test.go +++ b/internal/civisibility/integrations/gotesting/testing_test.go @@ -72,7 +72,10 @@ func TestMain(m *testing.M) { // execute the tests, because we are expecting some tests to fail and check the assertion later // we don't store the exit code from the test runner - RunM(m) + exitCode := RunM(m) + if exitCode != 1 { + panic("expected the exit code to be 1. We have a failing test on purpose.") + } // get all finished spans finishedSpans := mTracer.FinishedSpans() @@ -80,7 +83,7 @@ func TestMain(m *testing.M) { // 1 session span // 1 module span // 2 suite span (testing_test.go and reflections_test.go) - // 5 tests spans from testing_test.go + // 6 tests spans from testing_test.go // 7 sub stest spans from testing_test.go // 1 TestRetryWithPanic + 3 retry tests from testing_test.go // 1 TestRetryWithFail + 3 retry tests from testing_test.go @@ -89,8 +92,8 @@ func TestMain(m *testing.M) { // 5 tests from reflections_test.go // 2 benchmark spans (optional - require the -bench option) fmt.Printf("Number of spans received: %d\n", len(finishedSpans)) - if len(finishedSpans) < 36 { - panic("expected at least 36 finished spans, got " + strconv.Itoa(len(finishedSpans))) + if len(finishedSpans) < 37 { + panic("expected at least 37 finished spans, got " + strconv.Itoa(len(finishedSpans))) } sessionSpans := getSpansWithType(finishedSpans, constants.SpanTypeTestSession) @@ -117,8 +120,8 @@ func TestMain(m *testing.M) { testSpans := getSpansWithType(finishedSpans, constants.SpanTypeTest) fmt.Printf("Number of tests received: %d\n", len(testSpans)) showResourcesNameFromSpans(testSpans) - if len(testSpans) != 36 { - panic("expected exactly 36 test spans, got " + strconv.Itoa(len(testSpans))) + if len(testSpans) != 37 { + panic("expected exactly 37 test spans, got " + strconv.Itoa(len(testSpans))) } httpSpans := getSpansWithType(finishedSpans, ext.SpanTypeHTTP) @@ -311,6 +314,8 @@ func TestRetryAlwaysFail(t *testing.T) { t.Fatal("Always fail") } +func TestNormalPassingAfterRetryAlwaysFail(t *testing.T) {} + // BenchmarkFirst demonstrates benchmark instrumentation with sub-benchmarks. func BenchmarkFirst(gb *testing.B) {