Skip to content

Commit

Permalink
Limit concurrency for certain tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanotti committed Nov 7, 2023
1 parent dbfa694 commit 31b42b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,17 @@ func concurrencyTest(t *testing.T, numBatches, newBatchesInitialCapacity, batchC

ids := generateSequentialIds(10000)
wg := &sync.WaitGroup{}
// Limit the concurrency here to avoid creating too many goroutines and hit
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/9126
concurrencyLimiter := make(chan struct{}, 128)
defer close(concurrencyLimiter)
for i := 0; i < len(ids); i++ {
wg.Add(1)
concurrencyLimiter <- struct{}{}
go func(id pcommon.TraceID) {
batcher.AddToCurrentBatch(id)
wg.Done()
<-concurrencyLimiter
}(ids[i])
}

Expand Down
8 changes: 8 additions & 0 deletions processor/tailsamplingprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,24 @@ func TestConcurrentTraceArrival(t *testing.T) {
require.NoError(t, tsp.Shutdown(context.Background()))
}()

// Limit the concurrency here to avoid creating too many goroutines and hit
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/9126
concurrencyLimiter := make(chan struct{}, 128)
defer close(concurrencyLimiter)
for _, batch := range batches {
// Add the same traceId twice.
wg.Add(2)
concurrencyLimiter <- struct{}{}
go func(td ptrace.Traces) {
require.NoError(t, tsp.ConsumeTraces(context.Background(), td))
wg.Done()
<-concurrencyLimiter
}(batch)
concurrencyLimiter <- struct{}{}
go func(td ptrace.Traces) {
require.NoError(t, tsp.ConsumeTraces(context.Background(), td))
wg.Done()
<-concurrencyLimiter
}(batch)
}

Expand Down

0 comments on commit 31b42b8

Please sign in to comment.