Skip to content

Commit

Permalink
internal/civisibility/integrations/gotesting: change ddTestItem.error…
Browse files Browse the repository at this point in the history
… and ddTestItem.skipped bool type to an atomic.Int32 to avoid any race condition.
  • Loading branch information
tonyredondo committed Sep 11, 2024
1 parent 5068cf4 commit e32d8bb
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions internal/civisibility/integrations/gotesting/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type (

ddTestItem struct {
test integrations.DdTest
error bool
skipped bool
error atomic.Int32
skipped atomic.Int32
}
)

Expand Down Expand Up @@ -205,26 +205,23 @@ func instrumentTestingTFunc(f func(*testing.T)) func(*testing.T) {
// instrumentSetErrorInfo helper function to set an error in the `testing.T or testing.B` CI Visibility span
func instrumentSetErrorInfo(tb testing.TB, errType string, errMessage string, skip int) {
ciTestItem := getCiVisibilityTest(tb)
if ciTestItem != nil && !ciTestItem.error && ciTestItem.test != nil {
ciTestItem.error = true
if ciTestItem != nil && ciTestItem.error.CompareAndSwap(0, 1) && ciTestItem.test != nil {
ciTestItem.test.SetErrorInfo(errType, errMessage, utils.GetStacktrace(2+skip))
}
}

// instrumentCloseAndSkip helper function to close and skip with a reason a `testing.T or testing.B` CI Visibility span
func instrumentCloseAndSkip(tb testing.TB, skipReason string) {
ciTestItem := getCiVisibilityTest(tb)
if ciTestItem != nil && !ciTestItem.skipped && ciTestItem.test != nil {
ciTestItem.skipped = true
if ciTestItem != nil && ciTestItem.skipped.CompareAndSwap(0, 1) && ciTestItem.test != nil {
ciTestItem.test.CloseWithFinishTimeAndSkipReason(integrations.ResultStatusSkip, time.Now(), skipReason)
}
}

// instrumentSkipNow helper function to close and skip a `testing.T or testing.B` CI Visibility span
func instrumentSkipNow(tb testing.TB) {
ciTestItem := getCiVisibilityTest(tb)
if ciTestItem != nil && !ciTestItem.skipped && ciTestItem.test != nil {
ciTestItem.skipped = true
if ciTestItem != nil && ciTestItem.skipped.CompareAndSwap(0, 1) && ciTestItem.test != nil {
ciTestItem.test.Close(integrations.ResultStatusSkip)
}
}
Expand Down

0 comments on commit e32d8bb

Please sign in to comment.