From 82f4758b23a792d368ebe6e3a0106b021ca15fcb Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Fri, 4 Oct 2024 10:42:46 +0200 Subject: [PATCH 1/2] internal/civisibility: fixes the test parent status when the autoretry feature ended up with a failed test and after that there's a successful test. --- .../integrations/gotesting/instrumentation.go | 6 +++++- .../integrations/gotesting/testing_test.go | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 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..56da8f706d 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,7 +92,7 @@ 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 { + if len(finishedSpans) < 37 { panic("expected at least 36 finished spans, got " + strconv.Itoa(len(finishedSpans))) } @@ -117,7 +120,7 @@ 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 { + if len(testSpans) != 37 { panic("expected exactly 36 test spans, got " + strconv.Itoa(len(testSpans))) } @@ -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) { From 453eb0cca57a01fc607abcfdc7272834230d1927 Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Fri, 4 Oct 2024 10:59:37 +0200 Subject: [PATCH 2/2] internal/civisibility: update message in tests. --- internal/civisibility/integrations/gotesting/testing_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/civisibility/integrations/gotesting/testing_test.go b/internal/civisibility/integrations/gotesting/testing_test.go index 56da8f706d..2f41387280 100644 --- a/internal/civisibility/integrations/gotesting/testing_test.go +++ b/internal/civisibility/integrations/gotesting/testing_test.go @@ -93,7 +93,7 @@ func TestMain(m *testing.M) { // 2 benchmark spans (optional - require the -bench option) fmt.Printf("Number of spans received: %d\n", len(finishedSpans)) if len(finishedSpans) < 37 { - panic("expected at least 36 finished spans, got " + strconv.Itoa(len(finishedSpans))) + panic("expected at least 37 finished spans, got " + strconv.Itoa(len(finishedSpans))) } sessionSpans := getSpansWithType(finishedSpans, constants.SpanTypeTestSession) @@ -121,7 +121,7 @@ func TestMain(m *testing.M) { fmt.Printf("Number of tests received: %d\n", len(testSpans)) showResourcesNameFromSpans(testSpans) if len(testSpans) != 37 { - panic("expected exactly 36 test spans, got " + strconv.Itoa(len(testSpans))) + panic("expected exactly 37 test spans, got " + strconv.Itoa(len(testSpans))) } httpSpans := getSpansWithType(finishedSpans, ext.SpanTypeHTTP)