You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-17 01:12:45 +02:00
Add concurrency test for Exporter to otlploghttp (#5183)
* Add concurrency test for Exporter to otlploghttp * Update exporters/otlp/otlplog/otlploghttp/exporter_test.go Co-authored-by: Robert Pająk <pellared@hotmail.com> --------- Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
@ -5,6 +5,9 @@ package otlploghttp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -34,3 +37,41 @@ func TestExporterForceFlush(t *testing.T) {
|
|||||||
|
|
||||||
assert.NoError(t, e.ForceFlush(ctx), "ForceFlush")
|
assert.NoError(t, e.ForceFlush(ctx), "ForceFlush")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExporterConcurrentSafe(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
e, err := New(ctx)
|
||||||
|
require.NoError(t, err, "newExporter")
|
||||||
|
|
||||||
|
const goroutines = 10
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
runs := new(uint64)
|
||||||
|
for i := 0; i < goroutines; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
r := make([]log.Record, 1)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
_ = e.Export(ctx, r)
|
||||||
|
_ = e.ForceFlush(ctx)
|
||||||
|
atomic.AddUint64(runs, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
for atomic.LoadUint64(runs) == 0 {
|
||||||
|
runtime.Gosched()
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = e.Shutdown(ctx)
|
||||||
|
cancel()
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user