Skip to content

Commit

Permalink
ddtrace/tracer: address pr comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
knusbaum committed Jan 7, 2020
1 parent 708b3ad commit 3ebd601
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
9 changes: 3 additions & 6 deletions ddtrace/tracer/spancontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package tracer

import (
"context"
"fmt"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -112,7 +111,7 @@ func TestSpanTracePushOne(t *testing.T) {
assert.Equal(root, trace.spans[0], "the span is the one pushed before")

root.Finish()
tracer.flushAndWait(1)
tracer.flushAndWait(t, 1)

traces := transport.Traces()
assert.Len(traces, 1)
Expand Down Expand Up @@ -178,9 +177,7 @@ func TestSpanTracePushSeveral(t *testing.T) {
for _, span := range trace {
span.Finish()
}
fmt.Println("flush and wait")
tracer.flushAndWait(1)
fmt.Println("flush and wait DONE")
tracer.flushAndWait(t, 1)

traces := transport.Traces()
assert.Len(traces, 1)
Expand Down Expand Up @@ -210,7 +207,7 @@ func TestSpanFinishPriority(t *testing.T) {
child.Finish()
root.Finish()

tracer.flushAndWait(1)
tracer.flushAndWait(t, 1)

traces := transport.Traces()
assert.Len(traces, 1)
Expand Down
29 changes: 15 additions & 14 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (

// flushAndWait triggers a flush of the tracer's payload and waits for the transport to
// receive at least n traces. The wait will time out after 1 second.
func (t *tracer) flushAndWait(n int) {
func (t *tracer) flushAndWait(ts *testing.T, n int) {
transport := t.config.transport.(*dummyTransport)
t.flushChan <- struct{}{}
transport.waitFlush(n, 5*time.Second)
transport.waitFlush(ts, n)
}

func (t *tracer) newEnvSpan(service, env string) *span {
Expand Down Expand Up @@ -586,7 +586,7 @@ func TestTracerConcurrent(t *testing.T) {
}()

wg.Wait()
tracer.flushAndWait(3)
tracer.flushAndWait(t, 3)
traces := transport.Traces()
assert.Len(traces, 3)
assert.Len(traces[0], 1)
Expand All @@ -604,7 +604,7 @@ func TestTracerParentFinishBeforeChild(t *testing.T) {
parent := tracer.newRootSpan("pylons.request", "pylons", "/")
parent.Finish()

tracer.flushAndWait(1)
tracer.flushAndWait(t, 1)
traces := transport.Traces()
assert.Len(traces, 1)
assert.Len(traces[0], 1)
Expand All @@ -613,7 +613,7 @@ func TestTracerParentFinishBeforeChild(t *testing.T) {
child := tracer.newChildSpan("redis.command", parent)
child.Finish()

tracer.flushAndWait(1)
tracer.flushAndWait(t, 1)

traces = transport.Traces()
assert.Len(traces, 1)
Expand Down Expand Up @@ -647,7 +647,7 @@ func TestTracerConcurrentMultipleSpans(t *testing.T) {
}()

wg.Wait()
tracer.flushAndWait(2)
tracer.flushAndWait(t, 2)
traces := transport.Traces()
assert.Len(traces, 2)
assert.Len(traces[0], 2)
Expand Down Expand Up @@ -676,7 +676,7 @@ func TestTracerAtomicFlush(t *testing.T) {

root.Finish()

tracer.flushAndWait(1)
tracer.flushAndWait(t, 1)
traces = transport.Traces()
assert.Len(traces, 1)
assert.Len(traces[0], 4, "all spans should show up at once")
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestTracerRace(t *testing.T) {

wg.Wait()

tracer.flushAndWait(total)
tracer.flushAndWait(t, total)
traces := transport.Traces()
assert.Len(traces, total, "we should have exactly as many traces as expected")
for _, trace := range traces {
Expand Down Expand Up @@ -940,7 +940,7 @@ func TestTracerFlush(t *testing.T) {
root := tracer.StartSpan("root")
tracer.StartSpan("child.direct", ChildOf(root.Context())).Finish()
root.Finish()
tracer.flushAndWait(1)
tracer.flushAndWait(t, 1)

list := transport.Traces()
assert.Len(list, 1)
Expand All @@ -961,7 +961,7 @@ func TestTracerFlush(t *testing.T) {
t.Fatal(err)
}
tracer.StartSpan("child.extracted", ChildOf(sctx)).Finish()
tracer.flushAndWait(1)
tracer.flushAndWait(t, 1)
list := transport.Traces()
assert.Len(list, 1)
assert.Len(list[0], 1)
Expand Down Expand Up @@ -1098,17 +1098,18 @@ func decode(p *payload) (spanLists, error) {
return traces, err
}

func (t *dummyTransport) waitFlush(n int, timeout time.Duration) {
a := time.After(timeout)
func (t *dummyTransport) waitFlush(ts *testing.T, n int) {
a := time.After(1 * time.Second)
for {
select {
case <-a:
panic("timed out waiting for flush")
//panic("timed out waiting for flush")
ts.Fatalf("Timed out waiting for flush.")
default:
t.Lock()
l := len(t.traces)
t.Unlock()
if l >= n {
if l == n {
return
}
time.Sleep(5 * time.Millisecond)
Expand Down

0 comments on commit 3ebd601

Please sign in to comment.