Skip to content

Commit

Permalink
Fix flaky test - TestSpanProcessorWithOnDroppedSpanOption
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Xu <chen.x@uber.com>
  • Loading branch information
ChenX1993 committed May 10, 2023
1 parent 5c3c20d commit 27ce068
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmd/collector/app/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ func TestSpanProcessorContextPropagation(t *testing.T) {
}

func TestSpanProcessorWithOnDroppedSpanOption(t *testing.T) {
var droppedOperations []string
hasDropped := false
customOnDroppedSpan := func(span *model.Span) {
droppedOperations = append(droppedOperations, span.OperationName)
hasDropped = true
}

w := &blockingWriter{}
Expand All @@ -668,7 +668,8 @@ func TestSpanProcessorWithOnDroppedSpanOption(t *testing.T) {
Options.OnDroppedSpan(customOnDroppedSpan),
).(*spanProcessor)
defer p.Close()
// block the writer so that the first span is read from the queue and blocks the processor, and followings are dropped.
// block the writer so that the first span is read from the queue and blocks the processor. Either the second or
// the third is dropped since the queue capacity is just 1, but which one to drop is not guaranteed.
w.Lock()
defer w.Unlock()

Expand All @@ -679,5 +680,5 @@ func TestSpanProcessorWithOnDroppedSpanOption(t *testing.T) {
}, processor.SpansOptions{SpanFormat: processor.JaegerSpanFormat})

assert.NoError(t, err)
assert.Equal(t, []string{"op2", "op3"}, droppedOperations)
assert.True(t, hasDropped)
}

0 comments on commit 27ce068

Please sign in to comment.