Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concurrency test for Exporter to otlploghttp #5183

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions exporters/otlp/otlplog/otlploghttp/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ package otlploghttp

import (
"context"
"runtime"
"sync"
"sync/atomic"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -34,3 +37,41 @@ func TestExporterForceFlush(t *testing.T) {

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:
atomic.AddUint64(runs, 1)
_ = e.Export(ctx, r)
_ = e.ForceFlush(ctx)
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
}
}
}()
}

for atomic.LoadUint64(runs) == 0 {
runtime.Gosched()
}

_ = e.Shutdown(ctx)
cancel()
wg.Wait()
}
Loading