Commit 2d191f0
authored
Avoid SQL connection flakines in integration tests (#7854)
## Summary of changes
We are getting [the following
error](https://dev.azure.com/datadoghq/a51c4863-3eb4-4c5d-878a-58b41a049e4e/_apis/build/builds/191432/logs/22447)
in our integration tests:
```
2025-11-21T04:47:15.5891593Z 04:47:15 [DBG] Stack Trace:
2025-11-21T04:47:15.5892025Z 04:47:15 [DBG] at Datadog.Trace.TestHelpers.ExitCodeException.Throw(Int32 actualExitCode, Int32 expectedExitCode, String message) in /project/tracer/test/Datadog.Trace.TestHelpers/ExitCodeException.cs:line 44
2025-11-21T04:47:15.5892326Z 04:47:15 [DBG] at Datadog.Trace.TestHelpers.TestHelper.WaitForProcessResult(ProcessHelper helper, Int32 expectedExitCode, Boolean dumpChildProcesses) in /project/tracer/test/Datadog.Trace.TestHelpers.AutoInstrumentation/TestHelper.cs:line 212
2025-11-21T04:47:15.5892650Z 04:47:15 [DBG] at Datadog.Trace.TestHelpers.TestHelper.RunSampleAndWaitForExit(MockTracerAgent agent, String arguments, String packageVersion, String framework, Int32 aspNetCorePort, Boolean usePublishWithRID, String dotnetRuntimeArgs) in /project/tracer/test/Datadog.Trace.TestHelpers.AutoInstrumentation/TestHelper.cs:line 172
2025-11-21T04:47:15.5893224Z 04:47:15 [DBG] at Datadog.Trace.ClrProfiler.IntegrationTests.AdoNet.MicrosoftDataSqlClientTests.SubmitsTraces(String packageVersion, String metadataSchemaVersion, String propagation) in /project/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs:line 62
2025-11-21T04:47:15.5893396Z 04:47:15 [DBG] --- End of stack trace from previous location ---
2025-11-21T04:47:15.5893558Z 04:47:15 [DBG] Standard Output Messages:
2025-11-21T04:47:15.5893704Z 04:47:15 [DBG] Platform: Arm64
2025-11-21T04:47:15.5893857Z 04:47:15 [DBG] TargetPlatform: ARM64
2025-11-21T04:47:15.5894007Z 04:47:15 [DBG] Configuration: Release
2025-11-21T04:47:15.5894160Z 04:47:15 [DBG] TargetFramework: net8.0
2025-11-21T04:47:15.5894453Z 04:47:15 [DBG] .NET Core: True
2025-11-21T04:47:15.5894656Z 04:47:15 [DBG] Native Loader DLL: /project/shared/bin/monitoring-home/linux-arm64/Datadog.Trace.ClrProfiler.Native.so
2025-11-21T04:47:15.5894828Z 04:47:15 [DBG] Agent listener info: Traces at port 45159
2025-11-21T04:47:15.5895049Z 04:47:15 [DBG] Starting Application: /project/artifacts/publish/Samples.Microsoft.Data.SqlClient/release_net8.0_6.1.3/Samples.Microsoft.Data.SqlClient.dll
2025-11-21T04:47:15.5895201Z 04:47:15 [DBG] ProcessId: 6967
2025-11-21T04:47:15.5895347Z 04:47:15 [DBG] StandardOutput:
2025-11-21T04:47:15.5895700Z 04:47:15 [DBG] Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)
2025-11-21T04:47:15.5895896Z 04:47:15 [DBG] ---> System.Net.Sockets.SocketException (00000005, 0xFFFDFFFF): Name or service not known
2025-11-21T04:47:15.5896124Z 04:47:15 [DBG] at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, Nullable`1 startingTimestamp)
2025-11-21T04:47:15.5896315Z 04:47:15 [DBG] at System.Net.Dns.GetHostAddresses(String hostNameOrAddress, AddressFamily family)
2025-11-21T04:47:15.5896553Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.ManagedSni.SniTcpHandle.GetHostAddressesSortedByPreference(String serverName, SqlConnectionIPAddressPreference ipPreference)+MoveNext()
2025-11-21T04:47:15.5896817Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.ManagedSni.SniTcpHandle.Connect(String serverName, Int32 port, TimeoutTimer timeout, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo)
2025-11-21T04:47:15.5897128Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.ManagedSni.SniTcpHandle..ctor(String serverName, Int32 port, TimeoutTimer timeout, Boolean parallel, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo, Boolean tlsFirst, String hostNameInCertificate, String serverCertificateFilename)
2025-11-21T04:47:15.5897354Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
2025-11-21T04:47:15.5897591Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose)
2025-11-21T04:47:15.5897851Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, TimeoutTimer timeout, SqlConnectionString connectionOptions, Boolean withFailover)
2025-11-21T04:47:15.5898098Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, TimeoutTimer timeout, Boolean withFailover)
2025-11-21T04:47:15.5898394Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
2025-11-21T04:47:15.5898801Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
2025-11-21T04:47:15.5899380Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String access***, IDbConnectionPool pool, Func`3 access***Callback)
2025-11-21T04:47:15.5899800Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionPoolGroupProviderInfo poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
2025-11-21T04:47:15.5900076Z 04:47:15 [DBG] at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(IDbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
2025-11-21T04:47:15.5900319Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
2025-11-21T04:47:15.5900568Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
2025-11-21T04:47:15.5900866Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
2025-11-21T04:47:15.5901142Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 taskCompletionSource, DbConnectionOptions userOptions, DbConnectionInternal& connection)
2025-11-21T04:47:15.5901419Z 04:47:15 [DBG] at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
2025-11-21T04:47:15.5901688Z 04:47:15 [DBG] at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
2025-11-21T04:47:15.5902144Z 04:47:15 [DBG] at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
2025-11-21T04:47:15.5902394Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
2025-11-21T04:47:15.5902583Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
2025-11-21T04:47:15.5902754Z 04:47:15 [DBG] at Microsoft.Data.SqlClient.SqlConnection.Open()
2025-11-21T04:47:15.5903048Z 04:47:15 [DBG] at Samples.Microsoft.Data.SqlClient.Program.OpenConnection(Type connectionType) in D:\a\_work\1\s\tracer\test\test-applications\integrations\Samples.Microsoft.Data.SqlClient\Program.cs:line 49
```
CI tests occasionally fail with DNS/network errors (Error 11001, Class
20) when SQL Server isn't immediately available. These are
infrastructure issues, not test failures. By catching connection errors
and returning exit code 13, the test framework can skip these tests
instead of failing the build.
SQL exceptions during test execution (after successful connection) will
still fail the test as expected.
### Changes
- Catch `SqlException` during connection attempts in
`Samples.Microsoft.Data.SqlClient`
- Exit with code 13 (skip) when SQL Server is unavailable after 3 retry
attempts
- Refactor retry logic from `goto` to a clean `for` loop
- Improve logging to show attempt progress and detailed error
information
- Add some sleep time between tries
## Reason for change
## Implementation details
## Test coverage
## Other details
<!-- Fixes #{issue} -->
<!-- 1 parent d36555f commit 2d191f0
File tree
1 file changed
+79
-16
lines changed- tracer/test/test-applications/integrations/Samples.Microsoft.Data.SqlClient
1 file changed
+79
-16
lines changedLines changed: 79 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
| 34 | + | |
27 | 35 | | |
28 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
29 | 43 | | |
30 | 44 | | |
31 | 45 | | |
| |||
37 | 51 | | |
38 | 52 | | |
39 | 53 | | |
40 | | - | |
| 54 | + | |
41 | 55 | | |
42 | 56 | | |
43 | 57 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
53 | 61 | | |
54 | | - | |
| 62 | + | |
| 63 | + | |
55 | 64 | | |
56 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
57 | 72 | | |
58 | | - | |
59 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
60 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
61 | 105 | | |
62 | | - | |
63 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
64 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
65 | 128 | | |
66 | 129 | | |
67 | 130 | | |
0 commit comments