Skip to content

Commit a085f91

Browse files
authored
Sql Server Runtime Compatibility Check (open-telemetry#3314)
Refactor from compile time check to runtime check
1 parent 8310a7d commit a085f91

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

build/Build.Steps.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ DotNetBuildSettings BuildTestApplication(DotNetBuildSettings x) =>
211211
}
212212
}
213213

214-
foreach (var project in Solution.GetManagedUnitTestProjects())
214+
foreach (var project in Solution.GetManagedTestProjects())
215215
{
216216
if (TestTargetFramework != TargetFramework.NOT_SPECIFIED &&
217217
!project.GetTargetFrameworks().Contains(TestTargetFramework))
@@ -228,14 +228,6 @@ DotNetBuildSettings BuildTestApplication(DotNetBuildSettings x) =>
228228
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
229229
s => s.SetFramework(TestTargetFramework)));
230230
}
231-
232-
DotNetBuild(x => x
233-
.SetProjectFile(Solution.GetManagedIntegrationTestProject())
234-
.SetConfiguration(BuildConfiguration)
235-
.SetNoRestore(NoRestore)
236-
.SetPlatform(Platform)
237-
.When(TestTargetFramework != TargetFramework.NOT_SPECIFIED,
238-
s => s.SetFramework(TestTargetFramework)));
239231
});
240232

241233
Target CompileNativeDependenciesForManagedTests => _ => _
@@ -528,7 +520,6 @@ void RemoveFilesInNetFolderAvailableInAdditionalStore()
528520
{
529521
DotNetMSBuild(config => config
530522
.SetConfiguration(BuildConfiguration)
531-
.SetPlatform(Platform)
532523
.SetFilter(AndFilter(TestNameFilter(), ContainersFilter()))
533524
.SetBlameHangTimeout("5m")
534525
.EnableTrxLogOutput(GetResultsDirectory(project))

test/IntegrationTests/Helpers/EnvironmentTools.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public static string GetPlatform()
9292
return RuntimeInformation.ProcessArchitecture.ToString();
9393
}
9494

95+
public static bool IsX64()
96+
{
97+
return RuntimeInformation.ProcessArchitecture == Architecture.X64;
98+
}
99+
95100
public static string GetPlatformDir()
96101
{
97102
return RuntimeInformation.ProcessArchitecture switch

test/IntegrationTests/IntegrationTests.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@
44
<AddTestStrongNameAssemblyKeyOnNetFramework>true</AddTestStrongNameAssemblyKeyOnNetFramework>
55
<!-- No warn is needed for autogenerated code by protobuf: CS8981 - The type name only contains lower-cased ascii characters. -->
66
<NoWarn Condition="'$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net7.0'">CS8981</NoWarn>
7-
<Platforms>x64;ARM64</Platforms>
87
</PropertyGroup>
98

109
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
1110
<DefineConstants>$(DefineConstants);_WINDOWS</DefineConstants>
1211
</PropertyGroup>
1312

14-
<PropertyGroup Condition=" '$(Platform)' == 'ARM64' ">
15-
<DefineConstants>$(DefineConstants);_ARM64</DefineConstants>
16-
</PropertyGroup>
17-
18-
<PropertyGroup Condition=" '$(Platform)' == 'x64' ">
19-
<DefineConstants>$(DefineConstants);_X64</DefineConstants>
20-
</PropertyGroup>
21-
2213
<ItemGroup>
2314
<Reference Include="System.EnterpriseServices" Condition="$(TargetFramework.StartsWith('net4'))" />
2415
</ItemGroup>

test/IntegrationTests/SqlClientMicrosoftTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// SQL Server is supported on only AMD64
5-
#if _X64
6-
74
using IntegrationTests.Helpers;
85
using Xunit.Abstractions;
96

@@ -30,12 +27,15 @@ public static IEnumerable<object[]> GetData()
3027
#endif
3128
}
3229

33-
[Theory]
30+
[SkippableTheory]
3431
[Trait("Category", "EndToEnd")]
3532
[Trait("Containers", "Linux")]
3633
[MemberData(nameof(GetData))]
3734
public void SubmitTraces(string packageVersion)
3835
{
36+
// Skip the test if fixture does not support current platform
37+
_sqlServerFixture.SkipIfUnsupportedPlatform();
38+
3939
using var collector = new MockSpansCollector(Output);
4040
SetExporter(collector);
4141
collector.Expect("OpenTelemetry.Instrumentation.SqlClient");
@@ -49,5 +49,3 @@ public void SubmitTraces(string packageVersion)
4949
collector.AssertExpectations();
5050
}
5151
}
52-
53-
#endif

test/IntegrationTests/SqlClientSystemTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// SQL Server is supported on only AMD64
5-
#if _X64
6-
74
using IntegrationTests.Helpers;
85
using Xunit.Abstractions;
96

@@ -31,12 +28,15 @@ public static IEnumerable<object[]> GetData()
3128
}
3229
}
3330

34-
[Theory]
31+
[SkippableTheory]
3532
[Trait("Category", "EndToEnd")]
3633
[Trait("Containers", "Linux")]
3734
[MemberData(nameof(GetData))]
3835
public void SubmitTraces(string packageVersion, bool dbStatementForText)
3936
{
37+
// Skip the test if fixture does not support current platform
38+
_sqlServerFixture.SkipIfUnsupportedPlatform();
39+
4040
SetEnvironmentVariable("OTEL_DOTNET_AUTO_SQLCLIENT_SET_DBSTATEMENT_FOR_TEXT", dbStatementForText.ToString());
4141
using var collector = new MockSpansCollector(Output);
4242
SetExporter(collector);
@@ -59,5 +59,3 @@ public void SubmitTraces(string packageVersion, bool dbStatementForText)
5959
collector.AssertExpectations();
6060
}
6161
}
62-
63-
#endif

test/IntegrationTests/SqlServerCollection.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,25 @@ public class SqlServerFixture : IAsyncLifetime
2525

2626
public SqlServerFixture()
2727
{
28-
Port = TcpPortProvider.GetOpenPort();
28+
if (IsCurrentArchitectureSupported)
29+
{
30+
Port = TcpPortProvider.GetOpenPort();
31+
}
2932
}
3033

3134
public string Password { get; } = $"@{Guid.NewGuid().ToString("N")}";
3235

3336
public int Port { get; }
3437

38+
public bool IsCurrentArchitectureSupported { get; } = EnvironmentTools.IsX64();
39+
3540
public async Task InitializeAsync()
3641
{
42+
if (!IsCurrentArchitectureSupported)
43+
{
44+
return;
45+
}
46+
3747
_container = await LaunchSqlServerContainerAsync();
3848
}
3949

@@ -45,6 +55,14 @@ public async Task DisposeAsync()
4555
}
4656
}
4757

58+
public void SkipIfUnsupportedPlatform()
59+
{
60+
if (!IsCurrentArchitectureSupported)
61+
{
62+
throw new SkipException("SQL Server is supported only on AMD64.");
63+
}
64+
}
65+
4866
private static async Task ShutdownSqlServerContainerAsync(IContainer container)
4967
{
5068
await container.DisposeAsync();

0 commit comments

Comments
 (0)