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] Workaround integration test failures #2086

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using DotNet.Testcontainers.Containers;
using Microsoft.Data.SqlClient;
using OpenTelemetry.Tests;
using OpenTelemetry.Trace;
Expand All @@ -14,22 +12,16 @@

namespace OpenTelemetry.Instrumentation.SqlClient.Tests;

public sealed class SqlClientIntegrationTests : IAsyncLifetime
[Trait("CategoryName", "SqlIntegrationTests")]
public sealed class SqlClientIntegrationTests : IClassFixture<SqlClientIntegrationTestsFixture>
{
// The Microsoft SQL Server Docker image is not compatible with ARM devices, such as Macs with Apple Silicon.
private readonly IContainer databaseContainer = Architecture.Arm64.Equals(RuntimeInformation.ProcessArchitecture) ? new SqlEdgeBuilder().Build() : new MsSqlBuilder().Build();
private readonly SqlClientIntegrationTestsFixture fixture;

public Task InitializeAsync()
public SqlClientIntegrationTests(SqlClientIntegrationTestsFixture fixture)
{
return this.databaseContainer.StartAsync();
this.fixture = fixture;
}

public Task DisposeAsync()
{
return this.databaseContainer.DisposeAsync().AsTask();
}

[Trait("CategoryName", "SqlIntegrationTests")]
[EnabledOnDockerPlatformTheory(EnabledOnDockerPlatformTheoryAttribute.DockerPlatform.Linux)]
[InlineData(CommandType.Text, "select 1/1", false)]
[InlineData(CommandType.Text, "select 1/1", false, true)]
Expand Down Expand Up @@ -105,14 +97,14 @@ public void SuccessfulCommandTest(

private string GetConnectionString()
{
switch (this.databaseContainer)
switch (this.fixture.DatabaseContainer)
{
case SqlEdgeContainer container:
return container.GetConnectionString();
case MsSqlContainer container:
return container.GetConnectionString();
default:
throw new InvalidOperationException($"Container type ${this.databaseContainer.GetType().Name} not supported.");
throw new InvalidOperationException($"Container type '${this.fixture.DatabaseContainer.GetType().Name}' is not supported.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Runtime.InteropServices;
using DotNet.Testcontainers.Containers;
using Testcontainers.MsSql;
using Testcontainers.SqlEdge;
using Xunit;

namespace OpenTelemetry.Instrumentation.SqlClient.Tests;

public sealed class SqlClientIntegrationTestsFixture : IAsyncLifetime
{
// The Microsoft SQL Server Docker image is not compatible with ARM devices, such as Macs with Apple Silicon.
private readonly IContainer databaseContainer = Architecture.Arm64.Equals(RuntimeInformation.ProcessArchitecture) ? CreateSqlEdge() : CreateMsSql();

public IContainer DatabaseContainer => this.databaseContainer;

public Task InitializeAsync()
{
return this.databaseContainer.StartAsync();
}

public Task DisposeAsync()
{
return this.databaseContainer.DisposeAsync().AsTask();
}

private static SqlEdgeContainer CreateSqlEdge()
{
// Note: The Testcontainers.SqlEdge package has been deprecated. Seems
// it will not work with newer GItHub-hosted runners. Need to find an
// alternative solution. See:
// https://github.com/testcontainers/testcontainers-dotnet/pull/1265
return new SqlEdgeBuilder().Build();
}

private static MsSqlContainer CreateMsSql()
{
// Note: This "WithImage" line can most likely be removed when there is
// a new version (>3.10.0) of Testcontainers.MsSql released. See:
// https://github.com/testcontainers/testcontainers-dotnet/pull/1265
return new MsSqlBuilder()
.WithImage("mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04")
.Build();
}
}
Loading