-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to ensure domain-neutral is working (#1234)
* Add test to ensure domain-neutral is working * dotnet format fix for Command.cs * Remove sleep on the test Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: Piotr Kiełkowicz <[email protected]>
- Loading branch information
1 parent
a5fce34
commit 5b3fb8c
Showing
16 changed files
with
227 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// <copyright file="DomainNeutralTests.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> | ||
|
||
#if NETFRAMEWORK | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using IntegrationTests.Helpers; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace IntegrationTests; | ||
|
||
public class DomainNeutralTests : TestHelper | ||
{ | ||
public DomainNeutralTests(ITestOutputHelper output) | ||
: base("DomainNeutral", output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
[Trait("Category", "EndToEnd")] | ||
public async Task SubmitsTraces() | ||
{ | ||
EnvironmentTools.IsWindowsAdministrator().Should().BeTrue(); | ||
|
||
// Add the necessary assembly to the GAC so it can be loaded as domain-neutral. | ||
var instrumentationAssembly = Path.Combine( | ||
EnvironmentTools.GetSolutionDirectory(), | ||
"bin", | ||
"tracer-home", | ||
"net462", | ||
"OpenTelemetry.AutoInstrumentation.dll"); | ||
File.Exists(instrumentationAssembly).Should().BeTrue(); | ||
using var gacEntry = new GacEntry(instrumentationAssembly); | ||
|
||
// Domain-neutral depends on strong named assemblies to work, leverage some assets from | ||
// strong name testing in the current test. | ||
var assemblyPath = GetTestAssemblyPath(); | ||
var integrationsFile = Path.Combine(assemblyPath, "StrongNamedTestsIntegrations.json"); | ||
File.Exists(integrationsFile).Should().BeTrue(); | ||
|
||
SetEnvironmentVariable("OTEL_DOTNET_AUTO_INTEGRATIONS_FILE", integrationsFile); | ||
|
||
using var agent = new MockZipkinCollector(Output); | ||
|
||
RunTestApplication(agent.Port); | ||
|
||
const int expectedSpansCount = 1; | ||
var spans = await agent.WaitForSpansAsync(expectedSpansCount, TimeSpan.FromSeconds(5)); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
spans.Count.Should().Be(expectedSpansCount); | ||
|
||
spans.Count(s => s.Tags["validation"] == "StrongNamedValidation").Should().Be(1); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// <copyright file="GacEntry.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> | ||
|
||
#if NETFRAMEWORK | ||
using System; | ||
using System.EnterpriseServices.Internal; | ||
|
||
namespace IntegrationTests.Helpers; | ||
|
||
public class GacEntry : IDisposable | ||
{ | ||
private readonly string _assemblyPath; | ||
private readonly Publish _publish = new Publish(); | ||
|
||
public GacEntry(string assemblyPath) | ||
{ | ||
_assemblyPath = assemblyPath; | ||
_publish.GacInstall(assemblyPath); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_publish.GacRemove(_assemblyPath); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
test/test-applications/integrations/TestApplication.DomainNeutral/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// <copyright file="Program.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 System; | ||
using System.Reflection; | ||
|
||
namespace TestApplication.DomainNeutral; | ||
|
||
using TestLibrary.InstrumentationTarget; | ||
|
||
public static class Program | ||
{ | ||
[LoaderOptimization(LoaderOptimization.MultiDomain)] | ||
public static void Main(string[] args) | ||
{ | ||
var command = new Command(); | ||
command.Execute(); | ||
|
||
// Instrumentation assembly is expected to be already loaded from the GAC at this point. | ||
var instrumentationAssembly = Assembly.Load("OpenTelemetry.AutoInstrumentation") ?? throw new Exception("Instrumentation assembly was not loaded."); | ||
|
||
#if NETFRAMEWORK | ||
if (!instrumentationAssembly.GlobalAssemblyCache) | ||
{ | ||
throw new Exception("Instrumentation assembly was not loaded from the GAC"); | ||
} | ||
#endif | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...lications/integrations/TestApplication.DomainNeutral/TestApplication.DomainNeutral.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AddTestStrongNameAssemblyKeyOnNetFramework>true</AddTestStrongNameAssemblyKeyOnNetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\dependency-libs\TestLibrary.InstrumentationTarget\TestLibrary.InstrumentationTarget.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+596 Bytes
test/test-applications/integrations/TestApplication.StrongNamed/test-keypair.snk
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ependency-libs/TestLibrary.InstrumentationTarget/TestLibrary.InstrumentationTarget.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<AddTestStrongNameAssemblyKeyOnNetFramework>true</AddTestStrongNameAssemblyKeyOnNetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
Binary file added
BIN
+596 Bytes
...lications/integrations/dependency-libs/TestLibrary.InstrumentationTarget/test-keypair.snk
Binary file not shown.