Skip to content

Commit

Permalink
Fix flaky test TestBufferExporter/Shutdown/ContextCancelled (#5261)
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM committed Apr 25, 2024
1 parent fd6d4db commit 19ee6d4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sdk/log/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()

Expand Down

0 comments on commit 19ee6d4

Please sign in to comment.