1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-25 22:41:46 +02:00

Fixed race condition in OnEnd and added a unit test (#3951)

* Fixed race condition in OnEnd and added a test

* fixed code review comments

* fixed lint

* Update CHANGELOG.md

Co-authored-by: Robert Pająk <pellared@hotmail.com>

* Update sdk/trace/simple_span_processor_test.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Update sdk/trace/simple_span_processor_test.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Update sdk/trace/simple_span_processor_test.go

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* fixed panic check

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Kaushal Shah
2023-04-14 19:53:47 +05:30
committed by GitHub
parent eb2b89f335
commit 37388599eb
3 changed files with 33 additions and 3 deletions

View File

@@ -17,9 +17,12 @@ package trace_test
import (
"context"
"errors"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)
@@ -150,6 +153,32 @@ func TestSimpleSpanProcessorShutdownOnEndConcurrency(t *testing.T) {
<-done
}
func TestSimpleSpanProcessorShutdownOnEndRace(t *testing.T) {
exporter := &testExporter{}
ssp := sdktrace.NewSimpleSpanProcessor(exporter)
tp := basicTracerProvider(t)
tp.RegisterSpanProcessor(ssp)
var wg sync.WaitGroup
wg.Add(2)
span := func(spanName string) {
assert.NotPanics(t, func() {
defer wg.Done()
_, span := tp.Tracer("test").Start(context.Background(), spanName)
span.End()
})
}
go span("test-span-1")
go span("test-span-2")
wg.Wait()
assert.NoError(t, ssp.Shutdown(context.Background()))
assert.True(t, exporter.shutdown, "exporter shutdown")
}
func TestSimpleSpanProcessorShutdownHonorsContextDeadline(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
defer cancel()