You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-29 23:07:45 +02:00
Honor context deadline or cancellation in SimpleSpanProcessor.Shutdown (#1856)
* Honor context Done in SSP Shutdown * Update PR number in changelog * Update comment * Add tests * Make tests more concise * Restructure tests for readability
This commit is contained in:
@@ -16,7 +16,9 @@ package trace_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
@@ -142,3 +144,24 @@ func TestSimpleSpanProcessorShutdownOnEndConcurrency(t *testing.T) {
|
||||
stop <- struct{}{}
|
||||
<-done
|
||||
}
|
||||
|
||||
func TestSimpleSpanProcessorShutdownHonorsContextDeadline(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
|
||||
defer cancel()
|
||||
<-ctx.Done()
|
||||
|
||||
ssp := sdktrace.NewSimpleSpanProcessor(&testExporter{})
|
||||
if got, want := ssp.Shutdown(ctx), context.DeadlineExceeded; !errors.Is(got, want) {
|
||||
t.Errorf("SimpleSpanProcessor.Shutdown did not return %v, got %v", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleSpanProcessorShutdownHonorsContextCancel(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
ssp := sdktrace.NewSimpleSpanProcessor(&testExporter{})
|
||||
if got, want := ssp.Shutdown(ctx), context.Canceled; !errors.Is(got, want) {
|
||||
t.Errorf("SimpleSpanProcessor.Shutdown did not return %v, got %v", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user