Skip to content

Commit

Permalink
tracer TestUserMonitoring: Wait for goroutines before test completes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
evanj authored Oct 12, 2023
1 parent f72e6dd commit b0abc76
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,7 @@ func TestUserMonitoring(t *testing.T) {
tr := newTracer()
defer tr.Stop()
internal.SetGlobalTracer(tr)
defer internal.SetGlobalTracer(&internal.NoopTracer{})

t.Run("root", func(t *testing.T) {
s := tr.newRootSpan("root", "test", "test")
Expand Down Expand Up @@ -2319,19 +2320,26 @@ func TestUserMonitoring(t *testing.T) {
// This tests data races for trace.propagatingTags reads/writes through public API.
// The Go data race detector should not complain when running the test with '-race'.
t.Run("data-race", func(t *testing.T) {
wg := &sync.WaitGroup{}
wg.Add(2)

root := tr.newRootSpan("root", "test", "test")

go func() {
defer wg.Done()
for i := 0; i < 10000; i++ {
SetUser(root, "test")
}
}()
go func() {
defer wg.Done()
for i := 0; i < 10000; i++ {
tr.StartSpan("test", ChildOf(root.Context())).Finish()
}
}()

root.Finish()
wg.Wait()
})
}

Expand Down

0 comments on commit b0abc76

Please sign in to comment.