diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 694727c77e..b9921be05e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -164,7 +164,7 @@ jobs: run: ./build.cmd BuildNuGetPackages - name: Test NuGet Packages - run: ./build.cmd TestNuGetPackages + run: ./build.cmd TestNuGetPackages --containers windows - name: Upload Nuget Artifacts uses: actions/upload-artifact@v3.1.2 @@ -179,7 +179,9 @@ jobs: matrix: include: - machine: ubuntu-20.04 + containers: linux - machine: macos-11 + containers: none runs-on: ${{ matrix.machine }} steps: - uses: actions/checkout@v3.5.0 @@ -196,4 +198,4 @@ jobs: path: bin/nuget-artifacts/ - name: Test NuGet Packages - run: ./build.cmd TestNuGetPackages + run: ./build.cmd TestNuGetPackages --containers ${{ matrix.containers }} diff --git a/OpenTelemetry.AutoInstrumentation.sln b/OpenTelemetry.AutoInstrumentation.sln index 04f0c3e6b6..f0796878a5 100644 --- a/OpenTelemetry.AutoInstrumentation.sln +++ b/OpenTelemetry.AutoInstrumentation.sln @@ -180,11 +180,19 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGetPackagesTests", "test\NuGetPackagesTests\NuGetPackagesTests.csproj", "{AFD7582B-E9CD-4DF4-93B4-D5BBD7F539D0}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget-packages", "nuget-packages", "{2EF2F7CE-E56F-4B81-A5A5-277693529D43}" + ProjectSection(SolutionItems) = preProject + test\test-applications\nuget-packages\Directory.Build.props = test\test-applications\nuget-packages\Directory.Build.props + test\test-applications\nuget-packages\Directory.Build.targets = test\test-applications\nuget-packages\Directory.Build.targets + test\test-applications\nuget-packages\Directory.Packages.props = test\test-applications\nuget-packages\Directory.Packages.props + test\test-applications\nuget-packages\nuget.config = test\test-applications\nuget-packages\nuget.config + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.SelfContained", "test\test-applications\nuget-packages\TestApplication.SelfContained\TestApplication.SelfContained.csproj", "{25ED93D0-A70C-4A07-84D9-EF94115259C9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.EntityFrameworkCore.Pomelo.MySql", "test\test-applications\integrations\TestApplication.EntityFrameworkCore.Pomelo.MySql\TestApplication.EntityFrameworkCore.Pomelo.MySql.csproj", "{1D7E11AA-27B6-4863-B5EC-1F0ECC6979B2}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApplication.MongoDB.Nuget", "test\test-applications\nuget-packages\TestApplication.MongoDB.Nuget\TestApplication.MongoDB.Nuget.csproj", "{D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -849,6 +857,18 @@ Global {1D7E11AA-27B6-4863-B5EC-1F0ECC6979B2}.Release|x64.Build.0 = Release|x64 {1D7E11AA-27B6-4863-B5EC-1F0ECC6979B2}.Release|x86.ActiveCfg = Release|x86 {1D7E11AA-27B6-4863-B5EC-1F0ECC6979B2}.Release|x86.Build.0 = Release|x86 + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Debug|x64.ActiveCfg = Debug|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Debug|x64.Build.0 = Debug|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Debug|x86.ActiveCfg = Debug|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Debug|x86.Build.0 = Debug|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Release|Any CPU.Build.0 = Release|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Release|x64.ActiveCfg = Release|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Release|x64.Build.0 = Release|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Release|x86.ActiveCfg = Release|Any CPU + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -914,6 +934,7 @@ Global {2EF2F7CE-E56F-4B81-A5A5-277693529D43} = {91A299AD-6C09-4B7F-BD8B-A705D9BFC672} {25ED93D0-A70C-4A07-84D9-EF94115259C9} = {2EF2F7CE-E56F-4B81-A5A5-277693529D43} {1D7E11AA-27B6-4863-B5EC-1F0ECC6979B2} = {E409ADD3-9574-465C-AB09-4324D205CC7C} + {D1FD2D61-45AA-4A4E-82E3-4BEA55F16E2E} = {2EF2F7CE-E56F-4B81-A5A5-277693529D43} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F} diff --git a/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec b/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec index 19e918da3e..31bdb1d2b1 100644 --- a/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec +++ b/nuget/OpenTelemetry.AutoInstrumentation.Dependencies/OpenTelemetry.AutoInstrumentation.Dependencies.nuspec @@ -18,6 +18,7 @@ + diff --git a/test/IntegrationTests/Helpers/EnvironmentHelper.cs b/test/IntegrationTests/Helpers/EnvironmentHelper.cs index 3a17f69b0e..00cfbd562c 100644 --- a/test/IntegrationTests/Helpers/EnvironmentHelper.cs +++ b/test/IntegrationTests/Helpers/EnvironmentHelper.cs @@ -235,12 +235,21 @@ public string GetTestApplicationApplicationOutputDirectory(string packageVersion "app.publish"); } - return Path.Combine( + var nonSelfContainedOutputDir = Path.Combine( baseBinDirectory, packageVersion, EnvironmentTools.GetPlatform().ToLowerInvariant(), EnvironmentTools.GetBuildConfiguration(), targetFramework); + +#if NUGET_PACKAGE_TESTS + // The self-contained app is going to have an extra folder before it: the one + // with a RID like "win-x64", "linux-x64", etc. + + return Directory.GetDirectories(nonSelfContainedOutputDir)[0]; +#else + return nonSelfContainedOutputDir; +#endif } public string GetTargetFramework() diff --git a/test/IntegrationTests/Helpers/TestHelper.cs b/test/IntegrationTests/Helpers/TestHelper.cs index f3d0cb51ec..0d5f983512 100644 --- a/test/IntegrationTests/Helpers/TestHelper.cs +++ b/test/IntegrationTests/Helpers/TestHelper.cs @@ -107,12 +107,12 @@ public void EnableDefaultExporters() { testSettings ??= new(); using var process = StartTestApplication(testSettings); - Output.WriteLine($"ProcessName: " + process?.ProcessName); + Output.WriteLine($"ProcessName: {process?.ProcessName}"); using var helper = new ProcessHelper(process); process.Should().NotBeNull(); - bool processTimeout = !process!.WaitForExit((int)TestTimeout.ProcessExit.TotalMilliseconds); + var processTimeout = !process!.WaitForExit((int)TestTimeout.ProcessExit.TotalMilliseconds); if (processTimeout) { process.Kill(); @@ -133,7 +133,7 @@ public void EnableDefaultExporters() /// and returns the Process instance for further interaction. /// /// Test application process - public Process? StartTestApplication(TestSettings? testSettings = null) + public virtual Process? StartTestApplication(TestSettings? testSettings = null) { testSettings ??= new(); diff --git a/test/IntegrationTests/MongoDBTests.cs b/test/IntegrationTests/MongoDBTests.cs index b2c14713e1..40e8e32be0 100644 --- a/test/IntegrationTests/MongoDBTests.cs +++ b/test/IntegrationTests/MongoDBTests.cs @@ -15,17 +15,29 @@ // using IntegrationTests.Helpers; +#if NUGET_PACKAGE_TESTS +using NuGetPackagesTests; +#endif using Xunit.Abstractions; namespace IntegrationTests; [Collection(MongoDBCollection.Name)] -public class MongoDBTests : TestHelper +public class MongoDBTests +#if NUGET_PACKAGE_TESTS + : NugetTestHelper +#else + : TestHelper +#endif { private readonly MongoDBFixture _mongoDB; public MongoDBTests(ITestOutputHelper output, MongoDBFixture mongoDB) +#if NUGET_PACKAGE_TESTS + : base("MongoDB.Nuget", output) +#else : base("MongoDB", output) +#endif { _mongoDB = mongoDB; } @@ -33,7 +45,11 @@ public MongoDBTests(ITestOutputHelper output, MongoDBFixture mongoDB) [Theory] [Trait("Category", "EndToEnd")] [Trait("Containers", "Linux")] +#if NUGET_PACKAGE_TESTS + [InlineData("")] +#else [MemberData(nameof(LibraryVersion.MongoDB), MemberType = typeof(LibraryVersion))] +#endif public void SubmitsTraces(string packageVersion) { using var collector = new MockSpansCollector(Output); diff --git a/test/NuGetPackagesTests/NuGetPackagesTests.csproj b/test/NuGetPackagesTests/NuGetPackagesTests.csproj index cd7cf4c1e3..814b8eb4f4 100644 --- a/test/NuGetPackagesTests/NuGetPackagesTests.csproj +++ b/test/NuGetPackagesTests/NuGetPackagesTests.csproj @@ -4,11 +4,19 @@ $(DefineConstants);_WINDOWS + + + $(DefineConstants);NUGET_PACKAGE_TESTS + + + + + diff --git a/test/NuGetPackagesTests/NugetTestHelper.cs b/test/NuGetPackagesTests/NugetTestHelper.cs new file mode 100644 index 0000000000..ef5c7e2a26 --- /dev/null +++ b/test/NuGetPackagesTests/NugetTestHelper.cs @@ -0,0 +1,56 @@ +// +// 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. +// + +using System.Diagnostics; +using FluentAssertions; +using IntegrationTests.Helpers; +using Xunit.Abstractions; + +namespace NuGetPackagesTests; + +public abstract class NugetTestHelper : TestHelper +{ + protected NugetTestHelper(string testApplicationName, ITestOutputHelper output, string testApplicationType = "nuget-packages") + : base(testApplicationName, output, testApplicationType) + { + } + + public override Process? StartTestApplication(TestSettings? testSettings = null) + { + testSettings ??= new(); + + var instrumentationScriptExtension = EnvironmentTools.IsWindows() ? ".cmd" : ".sh"; + var instrumentationScriptPath = Path.Combine(EnvironmentHelper.GetTestApplicationApplicationOutputDirectory(testSettings.PackageVersion, testSettings.Framework), "instrument") + instrumentationScriptExtension; + + if (!File.Exists(instrumentationScriptPath)) + { + throw new Exception($"instrumentation script not found: {instrumentationScriptPath}"); + } + + // get path to test application that the profiler will attach to + var testApplicationPath = EnvironmentHelper.GetTestApplicationPath(testSettings.PackageVersion, testSettings.Framework); + if (!File.Exists(testApplicationPath)) + { + throw new Exception($"application not found: {testApplicationPath}"); + } + + Output.WriteLine($"Starting Application: {instrumentationScriptPath} {testApplicationPath}"); + + var args = $"{(EnvironmentHelper.IsCoreClr() ? EnvironmentHelper.GetTestApplicationExecutionSource() : string.Empty)} {testApplicationPath} {testSettings.Arguments ?? string.Empty}"; + + return InstrumentedProcessHelper.Start(instrumentationScriptPath, args, EnvironmentHelper); + } +} diff --git a/test/NuGetPackagesTests/SelfContainedTests.cs b/test/NuGetPackagesTests/SelfContainedTests.cs index e18cd2a996..8b9d8b2b6d 100644 --- a/test/NuGetPackagesTests/SelfContainedTests.cs +++ b/test/NuGetPackagesTests/SelfContainedTests.cs @@ -18,25 +18,17 @@ using IntegrationTests.Helpers; using Xunit.Abstractions; -namespace IntegrationTests; +namespace NuGetPackagesTests; [Trait("Category", "EndToEnd")] -public sealed class SelfContainedTests : TestHelper +public sealed class SelfContainedTests : NugetTestHelper { private readonly string _selfContainedAppDir; public SelfContainedTests(ITestOutputHelper output) - : base("SelfContained", output, "nuget-packages") + : base("SelfContained", output) { - var nonSelfContainedOutputDir = EnvironmentHelper - .GetTestApplicationApplicationOutputDirectory(); - - // The self-contained app is going to have an extra folder before it: the one - // with a RID like "win-x64", "linux-x64", etc. - var childrenDirs = Directory.GetDirectories(nonSelfContainedOutputDir); - childrenDirs.Should().ContainSingle(); - - _selfContainedAppDir = childrenDirs[0]; + _selfContainedAppDir = EnvironmentHelper.GetTestApplicationApplicationOutputDirectory(); } [Fact] diff --git a/test/test-applications/nuget-packages/Directory.Build.props b/test/test-applications/nuget-packages/Directory.Build.props index 68109858aa..d19839032a 100644 --- a/test/test-applications/nuget-packages/Directory.Build.props +++ b/test/test-applications/nuget-packages/Directory.Build.props @@ -19,4 +19,8 @@ ..\bin\$(MSBuildProjectName)\ + + + + diff --git a/test/test-applications/nuget-packages/TestApplication.MongoDB.Nuget/TestApplication.MongoDB.Nuget.csproj b/test/test-applications/nuget-packages/TestApplication.MongoDB.Nuget/TestApplication.MongoDB.Nuget.csproj new file mode 100644 index 0000000000..86818aa6b6 --- /dev/null +++ b/test/test-applications/nuget-packages/TestApplication.MongoDB.Nuget/TestApplication.MongoDB.Nuget.csproj @@ -0,0 +1,24 @@ + + + + Exe + true + + + + + + + + $(DefineConstants);MONGODB_2_15_OR_GREATER + + + false + false + + + + + + + diff --git a/test/test-applications/nuget-packages/TestApplication.SelfContained/Program.cs b/test/test-applications/nuget-packages/TestApplication.SelfContained/Program.cs index c847920af7..7a1747b99a 100644 --- a/test/test-applications/nuget-packages/TestApplication.SelfContained/Program.cs +++ b/test/test-applications/nuget-packages/TestApplication.SelfContained/Program.cs @@ -14,6 +14,9 @@ // limitations under the License. // +using TestApplication.Shared; + +ConsoleHelper.WriteSplashScreen(args); var httpClient = new HttpClient(); httpClient.Timeout = TimeSpan.FromSeconds(5); var response = await httpClient.GetAsync("http://example.com");