Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sql Server Runtime Compatibility Check #3314

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions build/Build.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 => _ => _
Expand Down Expand Up @@ -528,7 +520,6 @@ void RemoveFilesInNetFolderAvailableInAdditionalStore()
{
DotNetMSBuild(config => config
.SetConfiguration(BuildConfiguration)
.SetPlatform(Platform)
.SetFilter(AndFilter(TestNameFilter(), ContainersFilter()))
.SetBlameHangTimeout("5m")
.EnableTrxLogOutput(GetResultsDirectory(project))
Expand Down
5 changes: 5 additions & 0 deletions test/IntegrationTests/Helpers/EnvironmentTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions test/IntegrationTests/IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@
<AddTestStrongNameAssemblyKeyOnNetFramework>true</AddTestStrongNameAssemblyKeyOnNetFramework>
<!-- No warn is needed for autogenerated code by protobuf: CS8981 - The type name only contains lower-cased ascii characters. -->
<NoWarn Condition="'$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net7.0'">CS8981</NoWarn>
<Platforms>x64;ARM64</Platforms>
</PropertyGroup>

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

<PropertyGroup Condition=" '$(Platform)' == 'ARM64' ">
<DefineConstants>$(DefineConstants);_ARM64</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Platform)' == 'x64' ">
<DefineConstants>$(DefineConstants);_X64</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Reference Include="System.EnterpriseServices" Condition="$(TargetFramework.StartsWith('net4'))" />
</ItemGroup>
Expand Down
10 changes: 4 additions & 6 deletions test/IntegrationTests/SqlClientMicrosoftTests.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -30,12 +27,15 @@ public static IEnumerable<object[]> 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");
Expand All @@ -49,5 +49,3 @@ public void SubmitTraces(string packageVersion)
collector.AssertExpectations();
}
}

#endif
10 changes: 4 additions & 6 deletions test/IntegrationTests/SqlClientSystemTests.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -31,12 +28,15 @@ public static IEnumerable<object[]> 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);
Expand All @@ -59,5 +59,3 @@ public void SubmitTraces(string packageVersion, bool dbStatementForText)
collector.AssertExpectations();
}
}

#endif
20 changes: 19 additions & 1 deletion test/IntegrationTests/SqlServerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down
Loading