Skip to content

Commit 30f4797

Browse files
authored
Remove the guards around M.D.SqlClient V4 in tests (#7541)
## Summary of changes there was a piece of code skipping some tests in v4 and above of the library. Those were added in #2077 referencing dotnet/SqlClient#1390 However, this check has stayed in place ever since, stopping tests from being run on newer versions, even though the issue says that the issue was fixed in 4.0.1 if I read correctly. Since we don't run tests on v4.0.0 (the lowest 4 we run on is 4.0.6), we shouldn't need to check for this anymore. This might have been kept around because of an other issue where the sample app encountered an authentication issue trying to connect to the server in docker because the security certificate was not proper. Adding `TrustServerCertificate` on the connection string fixes this, and should allow us to run all tests always. ## Reason for change better test coverage for SqlClient ## Implementation details ## Test coverage ran a pipeline testing all package versions for this test here: https://dev.azure.com/datadoghq/dd-trace-dotnet/_build/results?buildId=187543 ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. -->
1 parent 20c5d82 commit 30f4797

File tree

4 files changed

+20
-43
lines changed

4 files changed

+20
-43
lines changed

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ services:
432432
- ELASTICSEARCH7_HOST=elasticsearch7:9200
433433
- ELASTICSEARCH6_HOST=elasticsearch6:9200
434434
- ELASTICSEARCH5_HOST=elasticsearch5:9200
435-
- SQLSERVER_CONNECTION_STRING=Server=sqlserver;User=sa;Password=Strong!Passw0rd
435+
- SQLSERVER_CONNECTION_STRING=Server=sqlserver;User=sa;Password=Strong!Passw0rd;TrustServerCertificate=true
436436
- POSTGRES_HOST=postgres
437437
- MYSQL_HOST=mysql
438438
- MYSQL_PORT=3306
@@ -713,7 +713,7 @@ services:
713713
- ELASTICSEARCH7_HOST=elasticsearch7_arm64:9200
714714
- ELASTICSEARCH6_HOST=elasticsearch7_arm64:9200
715715
- ELASTICSEARCH5_HOST=elasticsearch7_arm64:9200
716-
- SQLSERVER_CONNECTION_STRING=Server=sqledge_arm64;User=sa;Password=Strong!Passw0rd
716+
- SQLSERVER_CONNECTION_STRING=Server=sqledge_arm64;User=sa;Password=Strong!Passw0rd;TrustServerCertificate=true
717717
- POSTGRES_HOST=postgres_arm64
718718
- MYSQL_HOST=mysql_arm64
719719
- MYSQL_PORT=3306

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,7 @@ public async Task SubmitsTraces(
4747
// - IDbCommandGenericConstraint<SqlCommand>: 7 spans (1 group * 7 spans)
4848
// - IDbCommandGenericConstraint<SqlCommand>-netstandard: 7 spans (1 group * 7 spans)
4949

50-
// version 4.0 : 91 spans
51-
// - SqlCommand: 21 spans (3 groups * 7 spans)
52-
// - DbCommand: 21 spans (3 groups * 7 spans)
53-
// - IDbCommand: 7 spans (1 groups * 7 spans)
54-
// - DbCommand-netstandard: 21 spans (3 groups * 7 spans)
55-
// - IDbCommand-netstandard: 7 spans (1 groups * 7 spans)
56-
// - IDbCommandGenericConstraint<SqlCommand>: 7 spans (1 group * 7 spans)
57-
// - IDbCommandGenericConstraint<SqlCommand>-netstandard: 7 spans (1 group * 7 spans)
58-
var isVersion4 = !string.IsNullOrWhiteSpace(packageVersion)
59-
&& new Version(packageVersion) >= new Version("4.0.0");
60-
61-
if (isVersion4 && FrameworkDescription.Instance.OSPlatform != OSPlatformName.Windows)
62-
{
63-
// Version 4.0.0 has an issue on Linux https://github.com/dotnet/SqlClient/issues/1390
64-
return;
65-
}
66-
67-
var expectedSpanCount = isVersion4 ? 91 : 147;
50+
var expectedSpanCount = 147;
6851
const string dbType = "sql-server";
6952
const string expectedOperationName = dbType + ".query";
7053

tracer/test/test-applications/integrations/Samples.Microsoft.Data.SqlClient/Program.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,9 @@ private static async Task<int> Main()
1717

1818
using (var connection = OpenConnection(typeof(SqlConnection)))
1919
{
20-
if (connection is null)
21-
{
22-
Console.WriteLine("No connection could be established. Exiting with skip code (13)");
23-
return 13;
24-
}
25-
2620
await RelationalDatabaseTestHarness.RunAllAsync<SqlCommand>(connection, commandFactory, commandExecutor, cts.Token);
2721
}
2822

29-
// Version 4.0.0 causes a hard crash
30-
#if !SQLCLIENT_4
3123
// Test the result when the ADO.NET provider assembly is loaded through Assembly.LoadFile
3224
// On .NET Core this results in a new assembly being loaded whose types are not considered the same
3325
// as the types loaded through the default loading mechanism, potentially causing type casting issues in CallSite instrumentation
@@ -37,36 +29,39 @@ private static async Task<int> Main()
3729
// Do not use the strongly typed SqlCommandExecutor because the type casts will fail
3830
await RelationalDatabaseTestHarness.RunBaseClassesAsync(connection, commandFactory, cts.Token);
3931
}
40-
#endif
32+
4133
// allow time to flush
4234
await Task.Delay(2000, cts.Token);
4335
return 0;
4436
}
4537

4638
private static DbConnection OpenConnection(Type connectionType)
4739
{
48-
int numAttempts = 3;
40+
var remainingAttempts = 3;
4941
var connectionString = Environment.GetEnvironmentVariable("SQLSERVER_CONNECTION_STRING") ??
5042
@"Server=(localdb)\MSSQLLocalDB;Integrated Security=true;Connection Timeout=60";
5143

52-
for (int i = 0; i < numAttempts; i++)
44+
DbConnection connection = null;
45+
retry:
46+
try
5347
{
54-
DbConnection connection = null;
55-
56-
try
57-
{
58-
connection = Activator.CreateInstance(connectionType, connectionString) as DbConnection;
59-
connection.Open();
60-
return connection;
61-
}
62-
catch (Exception ex)
48+
connection = Activator.CreateInstance(connectionType, connectionString) as DbConnection;
49+
connection.Open();
50+
return connection;
51+
}
52+
catch (Exception ex)
53+
{
54+
if (remainingAttempts > 0)
6355
{
6456
Console.WriteLine(ex);
6557
connection?.Dispose();
58+
remainingAttempts--;
59+
goto retry;
6660
}
67-
}
6861

69-
return null;
62+
// else
63+
throw;
64+
}
7065
}
7166
}
7267
}

tracer/test/test-applications/integrations/Samples.Microsoft.Data.SqlClient/Samples.Microsoft.Data.SqlClient.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<ApiVersion Condition="'$(ApiVersion)' == ''">2.0.1</ApiVersion>
5-
<DefineConstants Condition="'$(ApiVersion)'&gt;='4.0.0'">$(DefineConstants);SQLCLIENT_4</DefineConstants>
65

76
<!-- Required to build multiple projects with the same Configuration|Platform -->
87
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

0 commit comments

Comments
 (0)