diff --git a/src/OpenTracing/Noop/NoopScopeManager.cs b/src/OpenTracing/Noop/NoopScopeManager.cs index 5d627f0..343c5f4 100644 --- a/src/OpenTracing/Noop/NoopScopeManager.cs +++ b/src/OpenTracing/Noop/NoopScopeManager.cs @@ -7,7 +7,7 @@ internal sealed class NoopScopeManager : IScopeManager { internal static readonly NoopScopeManager Instance = new NoopScopeManager(); - public IScope Active => null; + public IScope Active => NoopScope.Instance; private NoopScopeManager() { diff --git a/src/OpenTracing/Noop/NoopTracer.cs b/src/OpenTracing/Noop/NoopTracer.cs index 6d4bde1..1546935 100644 --- a/src/OpenTracing/Noop/NoopTracer.cs +++ b/src/OpenTracing/Noop/NoopTracer.cs @@ -8,7 +8,7 @@ internal sealed class NoopTracer : ITracer public IScopeManager ScopeManager => NoopScopeManager.Instance; - public ISpan ActiveSpan => null; + public ISpan ActiveSpan => NoopSpan.Instance; private NoopTracer() { diff --git a/test/OpenTracing.Tests/Noop/NoopScopeManagerTests.cs b/test/OpenTracing.Tests/Noop/NoopScopeManagerTests.cs new file mode 100644 index 0000000..ead0c85 --- /dev/null +++ b/test/OpenTracing.Tests/Noop/NoopScopeManagerTests.cs @@ -0,0 +1,17 @@ +using OpenTracing.Noop; +using Xunit; + +namespace OpenTracing.Tests.Noop +{ + public class NoopScopeManagerTests + { + + [Fact] + public void ActiveValueToleratesUse() + { + IScope active = NoopScopeManager.Instance.Active; + Assert.NotNull(active); + active.Dispose(); + } + } +} diff --git a/test/OpenTracing.Tests/Noop/NoopTests.cs b/test/OpenTracing.Tests/Noop/NoopTests.cs index 566f839..5482da0 100644 --- a/test/OpenTracing.Tests/Noop/NoopTests.cs +++ b/test/OpenTracing.Tests/Noop/NoopTests.cs @@ -21,15 +21,16 @@ public void Tracer_uses_NoopScopeManager() { var tracer = NoopTracerFactory.Create(); - Assert.IsType(tracer.ScopeManager); + Assert.Same(NoopScopeManager.Instance, tracer.ScopeManager); } [Fact] - public void Tracer_initially_has_no_active_span() + public void Tracer_ActiveSpan_is_NoopSpan() { var tracer = NoopTracerFactory.Create(); - Assert.Null(tracer.ActiveSpan); + var span = tracer.ActiveSpan; + Assert.Same(NoopSpan.Instance, span); } [Fact] @@ -39,7 +40,7 @@ public void BuildSpan_returns_NoopSpanBuilder() var spanBuilder = tracer.BuildSpan("noop"); - Assert.IsType(spanBuilder); + Assert.Same(NoopSpanBuilder.Instance, spanBuilder); } [Fact] @@ -61,7 +62,7 @@ public void StartActive_returns_NoopScope() var scope = tracer.BuildSpan("noop") .StartActive(finishSpanOnDispose: false); - Assert.IsType(scope); + Assert.Same(NoopScopeManager.NoopScope.Instance, scope); } [Fact] @@ -72,29 +73,29 @@ public void NoopScope_from_StartActive_has_NoopSpan() var scope = tracer.BuildSpan("noop") .StartActive(finishSpanOnDispose: false); - Assert.IsType(scope.Span); + Assert.Same(NoopSpan.Instance, scope.Span); } [Fact] - public void StartActive_does_NOT_set_Tracer_ActiveSpan() + public void StartActive_sets_Tracer_ActiveSpan() { var tracer = NoopTracerFactory.Create(); var scope = tracer.BuildSpan("noop") .StartActive(finishSpanOnDispose: false); - Assert.Null(tracer.ActiveSpan); + Assert.Same(NoopSpan.Instance, tracer.ActiveSpan); } [Fact] - public void StartActive_does_NOT_set_ScopeManager_Active() + public void StartActive_sets_ScopeManager_Active() { var tracer = NoopTracerFactory.Create(); var scope = tracer.BuildSpan("noop") .StartActive(finishSpanOnDispose: false); - Assert.Null(tracer.ScopeManager.Active); + Assert.Same(NoopScopeManager.NoopScope.Instance, tracer.ScopeManager.Active); } [Fact] @@ -104,7 +105,7 @@ public void Start_returns_NoopSpan() var span = tracer.BuildSpan("noop").Start(); - Assert.IsType(span); + Assert.Same(NoopSpan.Instance, span); } [Fact] @@ -119,23 +120,23 @@ public void Start_always_returns_same_Span() } [Fact] - public void Start_does_NOT_set_Tracer_ActiveSpan() + public void Start_sets_Tracer_ActiveSpan() { var tracer = NoopTracerFactory.Create(); var span = tracer.BuildSpan("noop").Start(); - Assert.Null(tracer.ActiveSpan); + Assert.Same(NoopSpan.Instance, tracer.ActiveSpan); } [Fact] - public void Start_does_NOT_set_ScopeManager_Active() + public void Start_sets_ScopeManager_Active() { var tracer = NoopTracerFactory.Create(); var span = tracer.BuildSpan("noop").Start(); - Assert.Null(tracer.ScopeManager.Active); + Assert.Same(NoopScopeManager.NoopScope.Instance, tracer.ScopeManager.Active); } [Fact] @@ -147,11 +148,11 @@ public void ScopeManager_returns_NoopScope_on_Activate() var scope = tracer.ScopeManager.Activate(span, finishSpanOnDispose: false); - Assert.IsType(scope); + Assert.Same(NoopScopeManager.NoopScope.Instance, scope); } [Fact] - public void ScopeManager_does_NOT_set_Active_on_Activate() + public void ScopeManager_sets_Active_on_Activate() { var tracer = NoopTracerFactory.Create(); @@ -159,8 +160,8 @@ public void ScopeManager_does_NOT_set_Active_on_Activate() tracer.ScopeManager.Activate(span, finishSpanOnDispose: false); - Assert.Null(tracer.ScopeManager.Active); - Assert.Null(tracer.ActiveSpan); + Assert.Same(NoopScopeManager.NoopScope.Instance, tracer.ScopeManager.Active); + Assert.Same(NoopSpan.Instance, tracer.ActiveSpan); } [Fact] @@ -170,7 +171,7 @@ public void Span_has_NoopSpanContext() var span = tracer.BuildSpan("noop").Start(); - Assert.IsType(span.Context); + Assert.Same(NoopSpanContext.Instance, span.Context); } [Fact] @@ -182,7 +183,7 @@ public void Extract_returns_NoopSpanContext() var spanContext = tracer.Extract(BuiltinFormats.TextMap, new TextMapExtractAdapter(carrier)); - Assert.IsType(spanContext); + Assert.Same(NoopSpanContext.Instance, spanContext); } [Fact] diff --git a/test/OpenTracing.Tests/Noop/NoopTracerTests.cs b/test/OpenTracing.Tests/Noop/NoopTracerTests.cs new file mode 100644 index 0000000..76fba1d --- /dev/null +++ b/test/OpenTracing.Tests/Noop/NoopTracerTests.cs @@ -0,0 +1,18 @@ +using OpenTracing.Noop; +using OpenTracing.Tag; +using Xunit; + +namespace OpenTracing.Tests.Noop +{ + public class NoopTracerTest + { + + [Fact] + public void ActiveSpanValueToleratesUse() + { + ISpan activeSpan = NoopTracer.Instance.ActiveSpan; + Assert.NotNull(activeSpan); + Tags.Error.Set(activeSpan, true); + } + } +}