dotnet / SqlClient

Microsoft.Data.SqlClient provides database connectivity to SQL Server for .NET applications.
MIT License
859 stars 288 forks source link

Fix flaky tests #3031

Open MichelZ opened 20 hours ago

MichelZ commented 20 hours ago

The following tests fail from time to time and should be considered "flaky" and investigated:

ConnectionExceptionTest.TestConnectionStateWithErrorClass20

This test has failed for me a couple of times with:


 [xUnit.net 00:00:57.04]     Microsoft.Data.SqlClient.ManualTesting.Tests.ConnectionExceptionTest.TestConnectionStateWithErrorClass20 [FAIL]
  [xUnit.net 00:00:57.04]       Assert.Equal() Failure: Values differ
  [xUnit.net 00:00:57.04]       Expected: 11
  [xUnit.net 00:00:57.04]       Actual:   20
  [xUnit.net 00:00:57.04]       Stack Trace:
  [xUnit.net 00:00:57.04]         /_/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs(43,0): at Microsoft.Data.SqlClient.ManualTesting.Tests.ConnectionExceptionTest.TestConnectionStateWithErrorClass20()
  [xUnit.net 00:00:57.04]            at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
  [xUnit.net 00:00:57.04]            at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
    Failed Microsoft.Data.SqlClient.ManualTesting.Tests.ConnectionExceptionTest.TestConnectionStateWithErrorClass20 [2 s]
##[error]EXEC(0,0): Error Message: 
EXEC : error Message:  [D:\a\_work\1\s\build.proj]
     Assert.Equal() Failure: Values differ
  Expected: 11
  Actual:   20
    Stack Trace:
       at Microsoft.Data.SqlClient.ManualTesting.Tests.ConnectionExceptionTest.TestConnectionStateWithErrorClass20() in /_/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs:line 43
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
     at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

EventCounterTest.EventCounter_ReclaimedConnectionsCounter_Functional

This one also fails frequently with a timeout, I don't know why though. Even after increasing the timeout to 30 seconds it still fails sometimes

 [xUnit.net 00:05:41.75]     Microsoft.Data.SqlClient.ManualTesting.Tests.EventCounterTest.EventCounter_ReclaimedConnectionsCounter_Functional [FAIL]
  [xUnit.net 00:05:41.75]       System.InvalidOperationException : Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
  [xUnit.net 00:05:41.75]       Stack Trace:
  [xUnit.net 00:05:41.75]         /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs(319,0): at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
  [xUnit.net 00:05:41.75]         /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs(963,0): at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
  [xUnit.net 00:05:41.75]         /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs(43,0): at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
  [xUnit.net 00:05:41.75]         /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs(1970,0): at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
  [xUnit.net 00:05:41.75]         /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs(1413,0): at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
  [xUnit.net 00:05:41.75]         /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs(1390,0): at Microsoft.Data.SqlClient.SqlConnection.Open()
  [xUnit.net 00:05:41.75]         /_/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs(167,0): at Microsoft.Data.SqlClient.ManualTesting.Tests.EventCounterTest.EventCounter_ReclaimedConnectionsCounter_Functional()
  [xUnit.net 00:05:41.75]            at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
  [xUnit.net 00:05:41.75]            at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
    Failed Microsoft.Data.SqlClient.ManualTesting.Tests.EventCounterTest.EventCounter_ReclaimedConnectionsCounter_Functional [30 s]
##[error]EXEC(0,0): Error Message: 
EXEC : error Message:  [D:\a\_work\1\s\build.proj]
     System.InvalidOperationException : Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
    Stack Trace:
       at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs:line 319
     at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs:line 963
     at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in /_/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs:line 43
     at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides) in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs:line 1970
     at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides) in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs:line 1413
     at Microsoft.Data.SqlClient.SqlConnection.Open() in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs:line 1390
     at Microsoft.Data.SqlClient.ManualTesting.Tests.EventCounterTest.EventCounter_ReclaimedConnectionsCounter_Functional() in /_/src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventCounterTest.cs:line 167
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
     at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)