From 2e5ea32ffb9f72d728f27d71fcbb2d8baff9382c Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 9 Apr 2024 08:50:07 -0700 Subject: [PATCH 1/2] Add concurrency test for Exporter to otlploghttp --- .../otlp/otlplog/otlploghttp/exporter_test.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/exporters/otlp/otlplog/otlploghttp/exporter_test.go b/exporters/otlp/otlplog/otlploghttp/exporter_test.go index 2474836c84a..030829182c6 100644 --- a/exporters/otlp/otlplog/otlploghttp/exporter_test.go +++ b/exporters/otlp/otlplog/otlploghttp/exporter_test.go @@ -5,6 +5,9 @@ package otlploghttp import ( "context" + "runtime" + "sync" + "sync/atomic" "testing" "github.com/stretchr/testify/assert" @@ -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) + } + } + }() + } + + for atomic.LoadUint64(runs) == 0 { + runtime.Gosched() + } + + _ = e.Shutdown(ctx) + cancel() + wg.Wait() +} From e56e128b912f2fb9235d95dab5c094c47c281489 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 9 Apr 2024 11:52:46 -0700 Subject: [PATCH 2/2] Update exporters/otlp/otlplog/otlploghttp/exporter_test.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- exporters/otlp/otlplog/otlploghttp/exporter_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporters/otlp/otlplog/otlploghttp/exporter_test.go b/exporters/otlp/otlplog/otlploghttp/exporter_test.go index 030829182c6..d818739a070 100644 --- a/exporters/otlp/otlplog/otlploghttp/exporter_test.go +++ b/exporters/otlp/otlplog/otlploghttp/exporter_test.go @@ -59,9 +59,9 @@ func TestExporterConcurrentSafe(t *testing.T) { case <-ctx.Done(): return default: - atomic.AddUint64(runs, 1) _ = e.Export(ctx, r) _ = e.ForceFlush(ctx) + atomic.AddUint64(runs, 1) } } }()