Skip to content

Commit 81dc038

Browse files
fix(internal/civisibility): propagate ITR tests-skipping enabled tag (#4736)
### What does this PR do? Propagates the CI Visibility `test.itr.tests_skipping.enabled` tag from the Go test session to module, suite, and test spans. The tag was already written on the session span when ITR was enabled. This change keeps that behavior and also adds the same value to the CI tags map after settings are loaded, so future module, suite, and test spans receive the same run-level value through the existing common-tag propagation path. It also adds regression coverage for the manual API propagation path and extends the gotesting ITR scenario to assert the tag on session, module, suite, and test spans. ### Motivation SDTEST-3761 Suite and test events need to carry the same ITR tests-skipping enabled value as the session event. Without this, downstream CI Visibility consumers can see the session-level setting but not the corresponding suite/test-level tag. ### Testing - [x] `go test ./internal/civisibility/integrations ./internal/civisibility/integrations/gotesting` - [x] `git diff --check` Co-authored-by: tonyredondo <[email protected]>
1 parent c3d9a3c commit 81dc038

3 files changed

Lines changed: 105 additions & 3 deletions

File tree

internal/civisibility/integrations/gotesting/testcontroller_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ func runIntelligentTestRunnerTests(m *testing.M) {
806806
if got := sessionSpans[0].Tag(constants.CodeCoverageEnabled); got != "false" {
807807
panic(fmt.Sprintf("expected %s=false when ITR is enabled without coverage, got %v", constants.CodeCoverageEnabled, got))
808808
}
809+
checkITRTestsSkippingEnabledTag(finishedSpans, "true")
809810

810811
fmt.Println("All tests passed.")
811812
os.Exit(0)
@@ -1063,6 +1064,29 @@ func checkCapabilitiesTags(finishedSpans []*mocktracer.Span) {
10631064
}
10641065
}
10651066

1067+
func checkITRTestsSkippingEnabledTag(finishedSpans []*mocktracer.Span, tagValue string) {
1068+
for _, spanType := range []struct {
1069+
name string
1070+
typ string
1071+
}{
1072+
{name: "session", typ: constants.SpanTypeTestSession},
1073+
{name: "module", typ: constants.SpanTypeTestModule},
1074+
{name: "suite", typ: constants.SpanTypeTestSuite},
1075+
{name: "test", typ: constants.SpanTypeTest},
1076+
} {
1077+
for _, sp := range getSpansWithType(finishedSpans, spanType.typ) {
1078+
if got := sp.Tag(constants.ITRTestsSkippingEnabled); got != tagValue {
1079+
panic(fmt.Sprintf("expected %s %s=%s on %s, got %v",
1080+
spanType.name,
1081+
constants.ITRTestsSkippingEnabled,
1082+
tagValue,
1083+
sp.Tag(ext.ResourceName),
1084+
got))
1085+
}
1086+
}
1087+
}
1088+
}
1089+
10661090
func checkLogs() {
10671091
// Assert that at least one logs payload has been sent by the library.
10681092
logsEntriesCount := len(logsEntries)

internal/civisibility/integrations/gotesting/testing.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ func (ddm *M) instrumentInternalTests(internalTests *[]testing.InternalTest) {
159159
if settings.ItrEnabled {
160160
coverageEnabled := settings.CodeCoverage && coverage.CanCollect()
161161
session.SetTag(constants.CodeCoverageEnabled, strconv.FormatBool(coverageEnabled))
162+
testsSkippingEnabled := strconv.FormatBool(settings.TestsSkipping)
163+
session.SetTag(constants.ITRTestsSkippingEnabled, testsSkippingEnabled)
164+
utils.AddCITagsMap(map[string]string{constants.ITRTestsSkippingEnabled: testsSkippingEnabled})
162165

163166
if settings.TestsSkipping {
164-
session.SetTag(constants.ITRTestsSkippingEnabled, "true")
165167
session.SetTag(constants.ITRTestsSkippingType, "test")
166168

167169
// Check if the test is going to be skipped by ITR
@@ -171,8 +173,6 @@ func (ddm *M) instrumentInternalTests(internalTests *[]testing.InternalTest) {
171173
session.SetTag(constants.ITRTestsSkipped, "false")
172174
}
173175
}
174-
} else {
175-
session.SetTag(constants.ITRTestsSkippingEnabled, "false")
176176
}
177177
}
178178

internal/civisibility/integrations/manual_api_mocktracer_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,74 @@ func TestTest(t *testing.T) {
342342
test.Close(ResultStatusSkip)
343343
}
344344

345+
func TestITRTestsSkippingEnabledPropagation(t *testing.T) {
346+
for _, tc := range []struct {
347+
name string
348+
setTag bool
349+
want string
350+
wantFound bool
351+
}{
352+
{
353+
name: "enabled",
354+
setTag: true,
355+
want: "true",
356+
wantFound: true,
357+
},
358+
{
359+
name: "disabled_tests_skipping",
360+
setTag: true,
361+
want: "false",
362+
wantFound: true,
363+
},
364+
{
365+
name: "disabled_itr",
366+
setTag: false,
367+
wantFound: false,
368+
},
369+
} {
370+
t.Run(tc.name, func(t *testing.T) {
371+
mockTracer.Reset()
372+
assert := assert.New(t)
373+
t.Cleanup(func() {
374+
utils.ResetCITags()
375+
utils.ResetCIMetrics()
376+
})
377+
378+
now := time.Now()
379+
session := createDDTestSession(now)
380+
if tc.setTag {
381+
session.SetTag(constants.ITRTestsSkippingEnabled, tc.want)
382+
utils.AddCITagsMap(map[string]string{constants.ITRTestsSkippingEnabled: tc.want})
383+
}
384+
module := session.GetOrCreateModule("my-module", WithTestModuleFramework("my-module-framework", "framework-version"), WithTestModuleStartTime(now))
385+
suite := module.GetOrCreateSuite("my-suite", WithTestSuiteStartTime(now))
386+
test := suite.CreateTest("my-test", WithTestStartTime(now))
387+
test.Close(ResultStatusPass)
388+
suite.Close()
389+
module.Close()
390+
session.Close(0)
391+
392+
finishedSpans := mockTracer.FinishedSpans()
393+
assert.Len(finishedSpans, 4)
394+
for _, spanType := range []string{
395+
constants.SpanTypeTestSession,
396+
constants.SpanTypeTestModule,
397+
constants.SpanTypeTestSuite,
398+
constants.SpanTypeTest,
399+
} {
400+
spans := manualAPISpansWithType(finishedSpans, spanType)
401+
if assert.Len(spans, 1) {
402+
if tc.wantFound {
403+
assert.Equal(tc.want, spans[0].Tag(constants.ITRTestsSkippingEnabled))
404+
} else {
405+
assert.NotContains(spans[0].Tags(), constants.ITRTestsSkippingEnabled)
406+
}
407+
}
408+
}
409+
})
410+
}
411+
}
412+
345413
func TestWithInnerFunc(t *testing.T) {
346414
mockTracer.Reset()
347415
assert := assert.New(t)
@@ -479,3 +547,13 @@ func containsSourceResolutionLogLine(lines []string, want string) bool {
479547
}
480548
return false
481549
}
550+
551+
func manualAPISpansWithType(spans []*mocktracer.Span, spanType string) []*mocktracer.Span {
552+
var result []*mocktracer.Span
553+
for _, span := range spans {
554+
if span.Tag(ext.SpanType) == spanType {
555+
result = append(result, span)
556+
}
557+
}
558+
return result
559+
}

0 commit comments

Comments
 (0)