Skip to content

Commit

Permalink
ddtrace/mocktracer: use lock in String method (#2229)
Browse files Browse the repository at this point in the history
ddtrace/mocktracer: use lock in String method

Co-authored-by: iharzhavarankau <izhavarankau@fubo.tv>
  • Loading branch information
phoenix2x and phoenix2x committed Sep 25, 2023
1 parent 992bbaf commit 6a938b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ddtrace/mocktracer/mockspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (s *mockspan) Finish(opts ...ddtrace.FinishOption) {

// String implements fmt.Stringer.
func (s *mockspan) String() string {
s.RLock()
defer s.RUnlock()
sc := s.context
return fmt.Sprintf(`
name: %s
Expand Down
8 changes: 8 additions & 0 deletions ddtrace/mocktracer/mockspan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ func TestSpanFinishTwice(t *testing.T) {
assert.Equal(len(s.tracer.finishedSpans), 1)
}

func TestSpanString(t *testing.T) {
s := basicSpan("http.request")
s.Finish(tracer.WithError(errors.New("some error")))

assert := assert.New(t)
assert.NotEmpty(s.String())
}

func TestSpanWithID(t *testing.T) {
spanID := uint64(123456789)
span := newMockTracer().StartSpan("", tracer.WithSpanID(spanID))
Expand Down

0 comments on commit 6a938b3

Please sign in to comment.