Skip to content

Commit

Permalink
Add tests for UnregisterSpanProcessor()
Browse files Browse the repository at this point in the history
  • Loading branch information
ash2k committed Mar 28, 2023
1 parent 32557d3 commit 1254293
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions sdk/trace/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,57 @@ func TestForceFlushAndShutdownTraceProviderWithoutProcessor(t *testing.T) {
assert.True(t, stp.isShutdown.Load())
}

func TestUnregisterFirst(t *testing.T) {
stp := NewTracerProvider()
sp1 := &basicSpanProcessor{}
sp2 := &basicSpanProcessor{}
sp3 := &basicSpanProcessor{}
stp.RegisterSpanProcessor(sp1)
stp.RegisterSpanProcessor(sp2)
stp.RegisterSpanProcessor(sp3)

stp.UnregisterSpanProcessor(sp1)

sps := stp.getSpanProcessors()
require.Len(t, sps, 2)
assert.Equal(t, sp2, sps[0].sp)
assert.Equal(t, sp3, sps[1].sp)
}

func TestUnregisterMiddle(t *testing.T) {
stp := NewTracerProvider()
sp1 := &basicSpanProcessor{}
sp2 := &basicSpanProcessor{}
sp3 := &basicSpanProcessor{}
stp.RegisterSpanProcessor(sp1)
stp.RegisterSpanProcessor(sp2)
stp.RegisterSpanProcessor(sp3)

stp.UnregisterSpanProcessor(sp2)

sps := stp.getSpanProcessors()
require.Len(t, sps, 2)
assert.Equal(t, sp1, sps[0].sp)
assert.Equal(t, sp3, sps[1].sp)
}

func TestUnregisterLast(t *testing.T) {
stp := NewTracerProvider()
sp1 := &basicSpanProcessor{}
sp2 := &basicSpanProcessor{}
sp3 := &basicSpanProcessor{}
stp.RegisterSpanProcessor(sp1)
stp.RegisterSpanProcessor(sp2)
stp.RegisterSpanProcessor(sp3)

stp.UnregisterSpanProcessor(sp3)

sps := stp.getSpanProcessors()
require.Len(t, sps, 2)
assert.Equal(t, sp1, sps[0].sp)
assert.Equal(t, sp2, sps[1].sp)
}

func TestShutdownTraceProvider(t *testing.T) {
stp := NewTracerProvider()
sp := &basicSpanProcessor{}
Expand Down

0 comments on commit 1254293

Please sign in to comment.