diff --git a/sdk/trace/provider_test.go b/sdk/trace/provider_test.go index e0945ddcf14e..7355944f52d0 100644 --- a/sdk/trace/provider_test.go +++ b/sdk/trace/provider_test.go @@ -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{}