Skip to content

Commit

Permalink
move tests from OpenTelemetry.Tests project to OpenTelemetry.Api.Tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMothra authored Apr 6, 2023
1 parent b449fa1 commit 807f703
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/OpenTelemetry.Api/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

[assembly: InternalsVisibleTo("OpenTelemetry" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Api.ProviderBuilderExtensions" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Api.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Shims.OpenTracing.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2" + AssemblyInfo.MoqPublicKey)]
Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions test/OpenTelemetry.Api.Tests/EventSourceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// <copyright file="EventSourceTest.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using OpenTelemetry.Internal;
using OpenTelemetry.Tests;
using Xunit;

namespace OpenTelemetry.Api.Tests
{
public class EventSourceTest
{
[Fact]
public void EventSourceTest_OpenTelemetryApiEventSource()
{
EventSourceTestHelper.MethodsAreImplementedConsistentlyWithTheirAttributes(OpenTelemetryApiEventSource.Log);
}
}
}
8 changes: 7 additions & 1 deletion test/OpenTelemetry.Api.Tests/OpenTelemetry.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Api\OpenTelemetry.Api.csproj" />
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Exporter.InMemory\OpenTelemetry.Exporter.InMemory.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\EventSourceTestHelper.cs" Link="Includes\EventSourceTestHelper.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\TestEventListener.cs" Link="Includes\TestEventListener.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\Utils.cs" Link="Includes\Utils.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions test/OpenTelemetry.Tests/EventSourceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ public void EventSourceTest_InstrumentationEventSource()
EventSourceTestHelper.MethodsAreImplementedConsistentlyWithTheirAttributes(InstrumentationEventSource.Log);
}

[Fact]
public void EventSourceTest_OpenTelemetryApiEventSource()
{
EventSourceTestHelper.MethodsAreImplementedConsistentlyWithTheirAttributes(OpenTelemetryApiEventSource.Log);
}

[Fact]
public void EventSourceTest_OpenTelemetrySdkEventSource()
{
Expand Down
27 changes: 21 additions & 6 deletions test/OpenTelemetry.Tests/Trace/ExceptionProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ Marshal.GetExceptionPointers returns non-zero.
}

Assert.Equal(StatusCode.Error, activity1.GetStatus().StatusCode);
Assert.Null(activity1.GetTagValue("otel.exception_pointers"));
Assert.Null(GetTagValue(activity1, "otel.exception_pointers"));
Assert.Equal(StatusCode.Error, activity2.GetStatus().StatusCode);
Assert.Null(activity2.GetTagValue("otel.exception_pointers"));
Assert.Null(GetTagValue(activity2, "otel.exception_pointers"));
Assert.Equal(StatusCode.Unset, activity3.GetStatus().StatusCode);
Assert.Null(activity3.GetTagValue("otel.exception_pointers"));
Assert.Null(GetTagValue(activity3, "otel.exception_pointers"));
Assert.Equal(StatusCode.Unset, activity4.GetStatus().StatusCode);
Assert.Null(activity4.GetTagValue("otel.exception_pointers"));
Assert.Null(GetTagValue(activity4, "otel.exception_pointers"));
Assert.Equal(StatusCode.Unset, activity5.GetStatus().StatusCode);
#if !NETFRAMEWORK
if (Environment.Is64BitProcess)
{
// In this rare case, the following Activity tag will not get cleaned up due to perf consideration.
Assert.NotNull(activity5.GetTagValue("otel.exception_pointers"));
Assert.NotNull(GetTagValue(activity5, "otel.exception_pointers"));
}
else
{
Assert.Null(activity5.GetTagValue("otel.exception_pointers"));
Assert.Null(GetTagValue(activity5, "otel.exception_pointers"));
}
#endif
}
Expand Down Expand Up @@ -132,5 +132,20 @@ public void ActivityStatusNotSetWhenExceptionProcessorNotEnabled()

Assert.Equal(StatusCode.Unset, activity.GetStatus().StatusCode);
}

private static object GetTagValue(Activity activity, string tagName)
{
Debug.Assert(activity != null, "Activity should not be null");

foreach (ref readonly var tag in activity.EnumerateTagObjects())
{
if (tag.Key == tagName)
{
return tag.Value;
}
}

return null;
}
}
}

0 comments on commit 807f703

Please sign in to comment.