Skip to content

Commit

Permalink
internal/civisibility/integrations/gotesting: fix functions to get an…
Browse files Browse the repository at this point in the history
…d store the civisibility test from `testing.T` and/or `testing.common` both structs implements `testing.TB` we want to get always the same test no matter the struct used.
  • Loading branch information
tonyredondo committed Sep 10, 2024
1 parent b486f39 commit f2eb2d2
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sync/atomic"
"testing"
"time"
"unsafe"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/integrations"
Expand All @@ -38,7 +39,7 @@ var (
instrumentationMapMutex sync.RWMutex

// ciVisibilityTests holds a map of *testing.T or *testing.B to civisibility.DdTest for tracking tests.
ciVisibilityTests = map[testing.TB]integrations.DdTest{}
ciVisibilityTests = map[unsafe.Pointer]integrations.DdTest{}

// ciVisibilityTestsMutex is a read-write mutex for synchronizing access to ciVisibilityTests.
ciVisibilityTestsMutex sync.RWMutex
Expand Down Expand Up @@ -68,7 +69,7 @@ func getCiVisibilityTest(tb testing.TB) integrations.DdTest {
ciVisibilityTestsMutex.RLock()
defer ciVisibilityTestsMutex.RUnlock()

if v, ok := ciVisibilityTests[tb]; ok {
if v, ok := ciVisibilityTests[reflect.ValueOf(tb).UnsafePointer()]; ok {
return v
}

Expand All @@ -79,7 +80,7 @@ func getCiVisibilityTest(tb testing.TB) integrations.DdTest {
func setCiVisibilityTest(tb testing.TB, ciTest integrations.DdTest) {
ciVisibilityTestsMutex.Lock()
defer ciVisibilityTestsMutex.Unlock()
ciVisibilityTests[tb] = ciTest
ciVisibilityTests[reflect.ValueOf(tb).UnsafePointer()] = ciTest
}

// instrumentTestingM helper function to instrument internalTests and internalBenchmarks in a `*testing.M` instance.
Expand Down

0 comments on commit f2eb2d2

Please sign in to comment.