1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-10-31 00:07:40 +02:00

Fix flaky test TestBufferExporter/Shutdown/ContextCancelled (#5261)

This commit is contained in:
Sam Xie
2024-04-25 08:46:39 -07:00
committed by GitHub
parent fd6d4db8c3
commit 19ee6d4775

View File

@@ -378,6 +378,13 @@ func TestBufferExporter(t *testing.T) {
})
t.Run("ContextCancelled", func(t *testing.T) {
// Discard error logs.
defer func(orig otel.ErrorHandler) {
otel.SetErrorHandler(orig)
}(otel.GetErrorHandler())
handler := otel.ErrorHandlerFunc(func(err error) {})
otel.SetErrorHandler(handler)
exp := newTestExporter(assert.AnError)
t.Cleanup(exp.Stop)
@@ -386,6 +393,9 @@ func TestBufferExporter(t *testing.T) {
t.Cleanup(func() { close(trigger) })
e := newBufferExporter(exp, 1)
// Make sure there is something to flush.
require.True(t, e.EnqueueExport(make([]Record, 1)))
ctx, cancel := context.WithCancel(context.Background())
cancel()