Skip to content

Commit

Permalink
sampling: fix flaky TestProcessLocalTailSampling (#4451)
Browse files Browse the repository at this point in the history
This would sometimes fail due to a timing issue,
where a sampling decision may be made part way
through processing a batch of events. Fix this
by starting the processor goroutines after
processing all events.
  • Loading branch information
axw committed Nov 23, 2020
1 parent d22b1a6 commit be1579a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions x-pack/apm-server/sampling/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ func TestProcessLocalTailSampling(t *testing.T) {

processor, err := sampling.NewProcessor(config)
require.NoError(t, err)
go processor.Run()
defer processor.Stop(context.Background())

traceID1 := "0102030405060708090a0b0c0d0e0f10"
traceID2 := "0102030405060708090a0b0c0d0e0f11"
Expand Down Expand Up @@ -171,6 +169,13 @@ func TestProcessLocalTailSampling(t *testing.T) {
require.NoError(t, err)
assert.Empty(t, out)

// Start periodic tail-sampling. We start the processor after processing
// events to ensure all events are processed before any local sampling
// decisions are made, such that we have a single tail-sampling decision
// to check.
go processor.Run()
defer processor.Stop(context.Background())

// We have configured 50% tail-sampling, so we expect a single trace ID
// to be published. Sampling is non-deterministic (weighted random), so
// we can't anticipate a specific trace ID.
Expand Down

0 comments on commit be1579a

Please sign in to comment.