You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-25 00:16:49 +02:00
Fix BSP context done tests (#1863)
This commit is contained in:
@ -418,31 +418,33 @@ func assertMaxSpanDiff(t *testing.T, want, got, maxDif int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type indefiniteExporter struct{}
|
||||||
|
|
||||||
|
func (indefiniteExporter) Shutdown(context.Context) error { return nil }
|
||||||
|
func (indefiniteExporter) ExportSpans(ctx context.Context, _ []*sdktrace.SpanSnapshot) error {
|
||||||
|
<-ctx.Done()
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
|
|
||||||
func TestBatchSpanProcessorForceFlushTimeout(t *testing.T) {
|
func TestBatchSpanProcessorForceFlushTimeout(t *testing.T) {
|
||||||
var bp testBatchExporter
|
|
||||||
bsp := sdktrace.NewBatchSpanProcessor(&bp)
|
|
||||||
// Add timeout to context to test deadline
|
// Add timeout to context to test deadline
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|
||||||
if err := bsp.ForceFlush(ctx); err == nil {
|
bsp := sdktrace.NewBatchSpanProcessor(indefiniteExporter{})
|
||||||
t.Error("expected context DeadlineExceeded error, got nil")
|
if got, want := bsp.ForceFlush(ctx), context.DeadlineExceeded; !errors.Is(got, want) {
|
||||||
} else if !errors.Is(err, context.DeadlineExceeded) {
|
t.Errorf("expected %q error, got %v", want, got)
|
||||||
t.Errorf("expected context DeadlineExceeded error, got %v", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBatchSpanProcessorForceFlushCancellation(t *testing.T) {
|
func TestBatchSpanProcessorForceFlushCancellation(t *testing.T) {
|
||||||
var bp testBatchExporter
|
|
||||||
bsp := sdktrace.NewBatchSpanProcessor(&bp)
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
// Cancel the context
|
// Cancel the context
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
if err := bsp.ForceFlush(ctx); err == nil {
|
bsp := sdktrace.NewBatchSpanProcessor(indefiniteExporter{})
|
||||||
t.Error("expected context canceled error, got nil")
|
if got, want := bsp.ForceFlush(ctx), context.Canceled; !errors.Is(got, want) {
|
||||||
} else if !errors.Is(err, context.Canceled) {
|
t.Errorf("expected %q error, got %v", want, got)
|
||||||
t.Errorf("expected context canceled error, got %v", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user