1
0
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:
Tyler Yahn
2021-04-28 17:15:00 +00:00
committed by GitHub
parent aeef8e00c2
commit f6a9279a86
3 changed files with 48 additions and 6 deletions

View File

@@ -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)
}
}