You've already forked opentelemetry-go
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user