Skip to content

Commit

Permalink
Skip the duck typing tests that won't work and add some others
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Feb 23, 2024
1 parent e4deba4 commit b3e4322
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
2 changes: 2 additions & 0 deletions tracer/src/Datadog.Trace.Manual/Datadog.Trace.Manual.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
</PropertyGroup>

<ItemGroup>
<!-- If you want to run the manual span benchmark or ducktyping unit tests />-->
<!-- <Compile Include="..\Datadog.Trace\DuckTyping\*.cs" Link="DuckTyping\%(Filename)%(Extension)" />-->
<Compile Include="..\Datadog.Trace\Ci\Benchmark*.cs" Link="Ci\%(Filename)%(Extension)" />
<Compile Include="..\Datadog.Trace\Ci\Coverage\Attributes\*.cs" Link="Ci\Coverage\Attributes\%(Filename)%(Extension)" />
<Compile Include="..\Datadog.Trace\Ci\Coverage\Exceptions\*.cs" Link="Ci\Coverage\Exceptions\%(Filename)%(Extension)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Datadog.Trace.Tests.ManualInstrumentation;
[TracerRestorer]
public class DuckTypingTests
{
private const string Skip = "We can't test these as-is because we rely on automatic instrumentation for ducktyping. To test these, import the DuckTyping folder into Datadog.Trace.Manual";
private readonly AsyncLocalScopeManager _scopeManager = new();
private readonly TracerSettings _settings = new() { StartupDiagnosticLogEnabled = false };
private readonly Tracer _tracer;
Expand All @@ -43,7 +44,7 @@ public DuckTypingTests()
_tracer = new Tracer(_settings, new Mock<IAgentWriter>().Object, new Mock<ITraceSampler>().Object, scopeManager: _scopeManager, statsd: null);
}

[Fact]
[Fact(Skip = Skip)]
public void CanDuckTypeManualSpanContextAsISpanContext()
{
var scope = _tracer.StartActiveInternal("manual");
Expand All @@ -59,7 +60,7 @@ public void CanDuckTypeManualSpanContextAsISpanContext()
manualContext.TraceId.Should().Be(spanContext.TraceId);
}

[Fact]
[Fact(Skip = Skip)]
public void CanDuckTypeManualScopeAsIScope()
{
var scope = _tracer.StartActiveInternal("manual");
Expand Down Expand Up @@ -91,7 +92,7 @@ public void CanDuckTypeManualScopeAsIScope()
manualScope.Dispose();
}

[Fact]
[Fact(Skip = Skip)]
public void CanDuckTypeManualTestSessionAsISession()
{
var session = TestSession.GetOrCreate("blah");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// <copyright file="ManualOnlyTests.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

extern alias DatadogTraceManual;

using System;
using FluentAssertions;
using Xunit;
using BenchmarkDiscreteStats = DatadogTraceManual::Datadog.Trace.Ci.BenchmarkDiscreteStats;
using BenchmarkHostInfo = DatadogTraceManual::Datadog.Trace.Ci.BenchmarkHostInfo;
using BenchmarkJobInfo = DatadogTraceManual::Datadog.Trace.Ci.BenchmarkJobInfo;
using BenchmarkMeasureType = DatadogTraceManual::Datadog.Trace.Ci.BenchmarkMeasureType;
using ManualScope = DatadogTraceManual::Datadog.Trace.ManualScope;
using ManualSpan = DatadogTraceManual::Datadog.Trace.ManualSpan;
using ManualSpanContext = DatadogTraceManual::Datadog.Trace.ManualSpanContext;
using ManualTest = DatadogTraceManual::Datadog.Trace.Ci.ManualTest;
using ManualTestModule = DatadogTraceManual::Datadog.Trace.Ci.ManualTestModule;
using ManualTestSession = DatadogTraceManual::Datadog.Trace.Ci.ManualTestSession;
using ManualTestSuite = DatadogTraceManual::Datadog.Trace.Ci.ManualTestSuite;
using TestParameters = DatadogTraceManual::Datadog.Trace.Ci.TestParameters;
using TestStatus = DatadogTraceManual::Datadog.Trace.Ci.TestStatus;

namespace Datadog.Trace.Tests.ManualInstrumentation;

public class ManualOnlyTests
{
[Fact]
public void CreatingAManualSpanDoesNotCrash()
{
using var scope = DatadogTraceManual::Datadog.Trace.Tracer.Instance.StartActive("manual");
scope.Should().BeOfType<ManualScope>().And.NotBeNull();

var span = scope.Span.Should().NotBeNull().And.BeOfType<ManualSpan>().Subject;
span.SetException(new Exception());
span.SetTag("James", "Bond");
span.GetTag("James").Should().BeNull();
span.OperationName.Should().BeNullOrEmpty();
span.ResourceName.Should().BeNullOrEmpty();

var context = span.Context.Should().NotBeNull().And.BeOfType<ManualSpanContext>().Subject;
context.Should().NotBeNull();
context.ServiceName.Should().BeNullOrEmpty();
}

[Fact]
public void CreatingAManualOnlyCiSessionDoesNotCrash()
{
var manualSession = DatadogTraceManual::Datadog.Trace.Ci.TestSession.GetOrCreate("some sesssion");
manualSession.Should().BeOfType<ManualTestSession>().And.NotBeNull();
manualSession.SetTag("session_key", "session_value");

var module = manualSession.CreateModule("somemodule");
module.Should().BeOfType<ManualTestModule>().And.NotBeNull();
module.SetTag("module_key", "module_value");
module.SetErrorInfo(new Exception());

var suite = module.GetOrCreateSuite("mysuite");
suite.Should().BeOfType<ManualTestSuite>().And.NotBeNull();
suite.SetTag("suite_key", "suite_value");

var test = suite.CreateTest("mytest");
test.Should().BeOfType<ManualTest>().And.NotBeNull();
test.SetTag("key", "value");

test.SetParameters(new TestParameters { Arguments = new(), Metadata = new() });
test.SetBenchmarkMetadata(new BenchmarkHostInfo() { RuntimeVersion = "123" }, new BenchmarkJobInfo() { Description = "weeble" });
var stats = new BenchmarkDiscreteStats(100, 100, 100, 100, 100, 0, 0, 0, 0, 100, 100, 100);
test.AddBenchmarkData(BenchmarkMeasureType.ApplicationLaunch, info: "something", in stats);

test.Close(TestStatus.Pass);
suite.Close();
module.Close();
manualSession.Close(TestStatus.Pass);
}
}
7 changes: 5 additions & 2 deletions tracer/test/benchmarks/Benchmarks.Trace/SpanBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ static SpanBenchmark()
/// <summary>
/// Starts and finishes scope benchmark using the manual instrumentation
/// </summary>
[Benchmark]
// Skipping this test because it's not representative any more - this relies on
// duck typing, which requires automatic instrumentation. If you want to
// benchmark it, first import the DuckTyping folder into Datadog.Trace.Manual
// [Benchmark]
public void ManualStartFinishScope()
{
var manualTracer = ManualTracer.DuckCast<ITracerProxy>();
Expand All @@ -65,7 +68,7 @@ public void ManualStartFinishScope()
SpanExtensionsSetTraceSamplingPriorityIntegration.OnMethodBegin<ManualTracer, ManualISpan>(ref span, SamplingPriority.UserReject);
}
}

/// <summary>
/// Starts and finishes span benchmark
/// </summary>
Expand Down

0 comments on commit b3e4322

Please sign in to comment.