From 7f8983a6445353b9312b57d7a33ba6cf7129d418 Mon Sep 17 00:00:00 2001 From: RassK Date: Mon, 11 Mar 2024 12:43:01 +0200 Subject: [PATCH] Refactor from compile time check to runtime check --- build/Build.Steps.cs | 11 +--------- .../Helpers/EnvironmentTools.cs | 5 +++++ test/IntegrationTests/IntegrationTests.csproj | 9 --------- .../SqlClientMicrosoftTests.cs | 10 ++++------ test/IntegrationTests/SqlClientSystemTests.cs | 10 ++++------ test/IntegrationTests/SqlServerCollection.cs | 20 ++++++++++++++++++- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/build/Build.Steps.cs b/build/Build.Steps.cs index 39648bac30..429e287236 100644 --- a/build/Build.Steps.cs +++ b/build/Build.Steps.cs @@ -211,7 +211,7 @@ partial class Build } } - foreach (var project in Solution.GetManagedUnitTestProjects()) + foreach (var project in Solution.GetManagedTestProjects()) { if (TestTargetFramework != TargetFramework.NOT_SPECIFIED && !project.GetTargetFrameworks().Contains(TestTargetFramework)) @@ -228,14 +228,6 @@ partial class Build .When(TestTargetFramework != TargetFramework.NOT_SPECIFIED, s => s.SetFramework(TestTargetFramework))); } - - DotNetBuild(x => x - .SetProjectFile(Solution.GetManagedIntegrationTestProject()) - .SetConfiguration(BuildConfiguration) - .SetNoRestore(NoRestore) - .SetPlatform(Platform) - .When(TestTargetFramework != TargetFramework.NOT_SPECIFIED, - s => s.SetFramework(TestTargetFramework))); }); Target CompileNativeDependenciesForManagedTests => _ => _ @@ -528,7 +520,6 @@ void RemoveFilesInNetFolderAvailableInAdditionalStore() { DotNetMSBuild(config => config .SetConfiguration(BuildConfiguration) - .SetPlatform(Platform) .SetFilter(AndFilter(TestNameFilter(), ContainersFilter())) .SetBlameHangTimeout("5m") .EnableTrxLogOutput(GetResultsDirectory(project)) diff --git a/test/IntegrationTests/Helpers/EnvironmentTools.cs b/test/IntegrationTests/Helpers/EnvironmentTools.cs index 97a06d2582..60a8f7e565 100644 --- a/test/IntegrationTests/Helpers/EnvironmentTools.cs +++ b/test/IntegrationTests/Helpers/EnvironmentTools.cs @@ -92,6 +92,11 @@ public static string GetPlatform() return RuntimeInformation.ProcessArchitecture.ToString(); } + public static bool IsX64() + { + return RuntimeInformation.ProcessArchitecture == Architecture.X64; + } + public static string GetPlatformDir() { return RuntimeInformation.ProcessArchitecture switch diff --git a/test/IntegrationTests/IntegrationTests.csproj b/test/IntegrationTests/IntegrationTests.csproj index 57aac7cba2..58f795bb9a 100644 --- a/test/IntegrationTests/IntegrationTests.csproj +++ b/test/IntegrationTests/IntegrationTests.csproj @@ -4,21 +4,12 @@ true CS8981 - x64;ARM64 $(DefineConstants);_WINDOWS - - $(DefineConstants);_ARM64 - - - - $(DefineConstants);_X64 - - diff --git a/test/IntegrationTests/SqlClientMicrosoftTests.cs b/test/IntegrationTests/SqlClientMicrosoftTests.cs index c1d68ac709..196978e49b 100644 --- a/test/IntegrationTests/SqlClientMicrosoftTests.cs +++ b/test/IntegrationTests/SqlClientMicrosoftTests.cs @@ -1,9 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -// SQL Server is supported on only AMD64 -#if _X64 - using IntegrationTests.Helpers; using Xunit.Abstractions; @@ -30,12 +27,15 @@ public static IEnumerable GetData() #endif } - [Theory] + [SkippableTheory] [Trait("Category", "EndToEnd")] [Trait("Containers", "Linux")] [MemberData(nameof(GetData))] public void SubmitTraces(string packageVersion) { + // Skip the test if fixture does not support current platform + _sqlServerFixture.SkipIfUnsupportedPlatform(); + using var collector = new MockSpansCollector(Output); SetExporter(collector); collector.Expect("OpenTelemetry.Instrumentation.SqlClient"); @@ -49,5 +49,3 @@ public void SubmitTraces(string packageVersion) collector.AssertExpectations(); } } - -#endif diff --git a/test/IntegrationTests/SqlClientSystemTests.cs b/test/IntegrationTests/SqlClientSystemTests.cs index 4ec7557dda..2327a3ff1a 100644 --- a/test/IntegrationTests/SqlClientSystemTests.cs +++ b/test/IntegrationTests/SqlClientSystemTests.cs @@ -1,9 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -// SQL Server is supported on only AMD64 -#if _X64 - using IntegrationTests.Helpers; using Xunit.Abstractions; @@ -31,12 +28,15 @@ public static IEnumerable GetData() } } - [Theory] + [SkippableTheory] [Trait("Category", "EndToEnd")] [Trait("Containers", "Linux")] [MemberData(nameof(GetData))] public void SubmitTraces(string packageVersion, bool dbStatementForText) { + // Skip the test if fixture does not support current platform + _sqlServerFixture.SkipIfUnsupportedPlatform(); + SetEnvironmentVariable("OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT", dbStatementForText.ToString()); using var collector = new MockSpansCollector(Output); SetExporter(collector); @@ -59,5 +59,3 @@ public void SubmitTraces(string packageVersion, bool dbStatementForText) collector.AssertExpectations(); } } - -#endif diff --git a/test/IntegrationTests/SqlServerCollection.cs b/test/IntegrationTests/SqlServerCollection.cs index c31cda444b..8dc2a1257b 100644 --- a/test/IntegrationTests/SqlServerCollection.cs +++ b/test/IntegrationTests/SqlServerCollection.cs @@ -25,15 +25,25 @@ public class SqlServerFixture : IAsyncLifetime public SqlServerFixture() { - Port = TcpPortProvider.GetOpenPort(); + if (IsCurrentArchitectureSupported) + { + Port = TcpPortProvider.GetOpenPort(); + } } public string Password { get; } = $"@{Guid.NewGuid().ToString("N")}"; public int Port { get; } + public bool IsCurrentArchitectureSupported { get; } = EnvironmentTools.IsX64(); + public async Task InitializeAsync() { + if (!IsCurrentArchitectureSupported) + { + return; + } + _container = await LaunchSqlServerContainerAsync(); } @@ -45,6 +55,14 @@ public async Task DisposeAsync() } } + public void SkipIfUnsupportedPlatform() + { + if (!IsCurrentArchitectureSupported) + { + throw new SkipException("SQL Server is supported only on AMD64."); + } + } + private static async Task ShutdownSqlServerContainerAsync(IContainer container) { await container.DisposeAsync();