Skip to content

Commit

Permalink
Add test to check bsp ignores OnEnd and ForceFlush post Shutdown` (
Browse files Browse the repository at this point in the history
…#1772)

* Add test to check bsp ignores OnEnd and ForceFlush post shutdown

* Add to CHANGELOG

* Check for err return value

* Stop test execution if there's error with shutting down bsp

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Use assert to check there's no error calling bsp.ForceFlush()

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* Import require

* Add error message for assertion on be.len()

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
cynthiakedu and MrAlias authored Apr 6, 2021
1 parent e9aaa04 commit 0d49b59
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- Adds test to check BatchSpanProcessor ignores `OnEnd` and `ForceFlush` post `Shutdown`. (#1772)
- Option `ExportTimeout` was added to batch span processor. (#1755)
- Adds semantic conventions for exceptions. (#1492)
- Added support for configuring OTLP/HTTP Endpoints, Headers, Compression and Timeout via the Environment Variables. (#1758)
Expand Down
26 changes: 26 additions & 0 deletions sdk/trace/batch_span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/trace"

Expand Down Expand Up @@ -289,6 +290,31 @@ func TestBatchSpanProcessorShutdown(t *testing.T) {
assert.Equal(t, 1, bp.shutdownCount)
}

func TestBatchSpanProcessorPostShutdown(t *testing.T) {
tp := basicTracerProvider(t)
be := testBatchExporter{}
bsp := sdktrace.NewBatchSpanProcessor(&be)

tp.RegisterSpanProcessor(bsp)
tr := tp.Tracer("Normal")

generateSpan(t, true, tr, testOption{
o: []sdktrace.BatchSpanProcessorOption{
sdktrace.WithMaxExportBatchSize(50),
},
genNumSpans: 60,
})

require.NoError(t, bsp.Shutdown(context.Background()), "shutting down BatchSpanProcessor")
lenJustAfterShutdown := be.len()

_, span := tr.Start(context.Background(), "foo")
span.End()
assert.NoError(t, bsp.ForceFlush(context.Background()), "force flushing BatchSpanProcessor")

assert.Equal(t, lenJustAfterShutdown, be.len(), "OnEnd and ForceFlush should have no effect after Shutdown")
}

func TestBatchSpanProcessorForceFlushSucceeds(t *testing.T) {
te := testBatchExporter{}
tp := basicTracerProvider(t)
Expand Down

0 comments on commit 0d49b59

Please sign in to comment.