mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-22 03:38:42 +02:00
SDK: Add Shutdown test for Span Processor (#169)
* SDK: Add Shutdown test for Span Processor * SDK: Shutdown test for Span Processor. Review fixes
This commit is contained in:
parent
ef5d2cbb06
commit
93c667978d
@ -202,3 +202,19 @@ func getSpanContext() core.SpanContext {
|
|||||||
TraceFlags: 0x1,
|
TraceFlags: 0x1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBatchSpanProcessorShutdown(t *testing.T) {
|
||||||
|
bsp, err := sdktrace.NewBatchSpanProcessor(&testBatchExporter{})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error while creating processor\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if bsp == nil {
|
||||||
|
t.Fatalf("Error creating new instance of BatchSpanProcessor\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
bsp.Shutdown()
|
||||||
|
|
||||||
|
// Multiple call to Shutdown() should not panic.
|
||||||
|
bsp.Shutdown()
|
||||||
|
}
|
||||||
|
@ -75,3 +75,12 @@ func TestSimpleSpanProcessorOnEnd(t *testing.T) {
|
|||||||
t.Errorf("SimplerSpanProcessor OnEnd() check: got %+v, want %+v\n", gotTraceID, wantTraceID)
|
t.Errorf("SimplerSpanProcessor OnEnd() check: got %+v, want %+v\n", gotTraceID, wantTraceID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSimpleSpanProcessorShutdown(t *testing.T) {
|
||||||
|
ssp := sdktrace.NewSimpleSpanProcessor(&testExporter{})
|
||||||
|
if ssp == nil {
|
||||||
|
t.Errorf("Error creating new instance of SimpleSpanProcessor\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
ssp.Shutdown()
|
||||||
|
}
|
||||||
|
@ -109,8 +109,47 @@ func TestUnregisterSpanProcessorWhileSpanIsActive(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(rghetia): Add Shutdown test when it is implemented.
|
func TestSpanProcessorShutdown(t *testing.T) {
|
||||||
func TestShutdown(t *testing.T) {
|
name := "Increment shutdown counter of a span processor"
|
||||||
|
sp := NewTestSpanProcessor()
|
||||||
|
if sp == nil {
|
||||||
|
t.Fatalf("Error creating new instance of TestSpanProcessor\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
wantCount := sp.shutdownCount + 1
|
||||||
|
sp.Shutdown()
|
||||||
|
|
||||||
|
gotCount := sp.shutdownCount
|
||||||
|
if wantCount != gotCount {
|
||||||
|
t.Errorf("%s: wrong counter: got %d, want %d\n", name, gotCount, wantCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMultipleUnregisterSpanProcessorCalls(t *testing.T) {
|
||||||
|
name := "Increment shutdown counter after each UnregisterSpanProcessor call"
|
||||||
|
sp := NewTestSpanProcessor()
|
||||||
|
if sp == nil {
|
||||||
|
t.Fatalf("Error creating new instance of TestSpanProcessor\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
wantCount := sp.shutdownCount + 1
|
||||||
|
|
||||||
|
sdktrace.RegisterSpanProcessor(sp)
|
||||||
|
sdktrace.UnregisterSpanProcessor(sp)
|
||||||
|
|
||||||
|
gotCount := sp.shutdownCount
|
||||||
|
if wantCount != gotCount {
|
||||||
|
t.Errorf("%s: wrong counter: got %d, want %d\n", name, gotCount, wantCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple UnregisterSpanProcessor triggers multiple Shutdown calls.
|
||||||
|
wantCount = wantCount + 1
|
||||||
|
sdktrace.UnregisterSpanProcessor(sp)
|
||||||
|
|
||||||
|
gotCount = sp.shutdownCount
|
||||||
|
if wantCount != gotCount {
|
||||||
|
t.Errorf("%s: wrong counter: got %d, want %d\n", name, gotCount, wantCount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestSpanProcessor() *testSpanProcesor {
|
func NewTestSpanProcessor() *testSpanProcesor {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user