Skip to content

Commit

Permalink
internal/civisibility: fixes the test parent status when the auto-ret…
Browse files Browse the repository at this point in the history
…ry feature ended up with a failed test and then a successful test. (#2910)
  • Loading branch information
tonyredondo authored Oct 4, 2024
1 parent d3f686e commit d50070a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
17 changes: 11 additions & 6 deletions internal/civisibility/integrations/gotesting/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ 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()

// 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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {

Expand Down

0 comments on commit d50070a

Please sign in to comment.