Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Pham committed Jul 16, 2021
1 parent 276eaaf commit 68dcbb6
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 127 deletions.
48 changes: 48 additions & 0 deletions src/Microsoft.Data.SqlClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,54 @@ Global
{E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|x64.Build.0 = Release|Any CPU
{E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|x86.ActiveCfg = Release|Any CPU
{E4C08DCE-DC29-4FEB-B655-1E7287DB5A2B}.Release|x86.Build.0 = Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Debug|x64.ActiveCfg = Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Debug|x64.Build.0 = Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Debug|x86.ActiveCfg = Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Debug|x86.Build.0 = Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Debug|Any CPU.ActiveCfg = net461-Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Debug|Any CPU.Build.0 = net461-Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Debug|x64.ActiveCfg = net461-Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Debug|x64.Build.0 = net461-Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Debug|x86.ActiveCfg = net461-Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Debug|x86.Build.0 = net461-Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Release|Any CPU.ActiveCfg = net461-Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Release|Any CPU.Build.0 = net461-Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Release|x64.ActiveCfg = net461-Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Release|x64.Build.0 = net461-Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Release|x86.ActiveCfg = net461-Release|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.net461-Release|x86.Build.0 = net461-Release|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Debug|Any CPU.ActiveCfg = netcoreapp2.1-Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Debug|Any CPU.Build.0 = netcoreapp2.1-Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Debug|x64.ActiveCfg = netcoreapp2.1-Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Debug|x64.Build.0 = netcoreapp2.1-Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Debug|x86.ActiveCfg = netcoreapp2.1-Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Debug|x86.Build.0 = netcoreapp2.1-Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Release|Any CPU.ActiveCfg = netcoreapp2.1-Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Release|Any CPU.Build.0 = netcoreapp2.1-Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Release|x64.ActiveCfg = netcoreapp2.1-Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Release|x64.Build.0 = netcoreapp2.1-Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Release|x86.ActiveCfg = netcoreapp2.1-Release|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp2.1-Release|x86.Build.0 = netcoreapp2.1-Release|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Debug|Any CPU.ActiveCfg = netcoreapp3.1-Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Debug|Any CPU.Build.0 = netcoreapp3.1-Debug|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Debug|x64.ActiveCfg = netcoreapp3.1-Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Debug|x64.Build.0 = netcoreapp3.1-Debug|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Debug|x86.ActiveCfg = netcoreapp3.1-Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Debug|x86.Build.0 = netcoreapp3.1-Debug|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Release|Any CPU.ActiveCfg = netcoreapp3.1-Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Release|Any CPU.Build.0 = netcoreapp3.1-Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Release|x64.ActiveCfg = netcoreapp3.1-Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Release|x64.Build.0 = netcoreapp3.1-Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Release|x86.ActiveCfg = netcoreapp3.1-Release|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.netcoreapp3.1-Release|x86.Build.0 = netcoreapp3.1-Release|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Release|Any CPU.Build.0 = Release|Any CPU
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Release|x64.ActiveCfg = Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Release|x64.Build.0 = Release|x64
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Release|x86.ActiveCfg = Release|x86
{B499E477-C9B1-4087-A5CF-5C762D90E433}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class ConnectionPoolConnectionStringProvider : IEnumerable<object[]>
{
private static readonly string _TCPConnectionString = (new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString) { MultipleActiveResultSets = false, Pooling = true }).ConnectionString;
private static readonly string _tcpMarsConnStr = (new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString) { MultipleActiveResultSets = true, Pooling = true }).ConnectionString;
private static bool IsNotAzureSynapse = DataTestUtility.IsNotAzureSynapse();

public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { _TCPConnectionString, false };
yield return new object[] { _tcpMarsConnStr, IsNotAzureSynapse ? false : true };
yield return new object[] { _TCPConnectionString};
if (DataTestUtility.IsNotAzureSynapse())
{
yield return new object[] { _tcpMarsConnStr};
}
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
Expand All @@ -37,13 +39,8 @@ public static class ConnectionPoolTest
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void BasicConnectionPoolingTest(string connectionString, bool marsAndAzureSynapse)
public static void BasicConnectionPoolingTest(string connectionString)
{
if (marsAndAzureSynapse)
{
return;
}

InternalConnectionWrapper internalConnection;
ConnectionPoolWrapper connectionPool;
using (SqlConnection connection = new SqlConnection(connectionString))
Expand Down Expand Up @@ -119,58 +116,13 @@ public static void AccessTokenConnectionPoolingTest()
connection4.Close();
}

#if DEBUG
/// <summary>
/// Tests if killing the connection using the InternalConnectionWrapper is working
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void KillConnectionTest(string connectionString, bool marsAndAzureSynapse)
{
if (marsAndAzureSynapse || !DataTestUtility.IsUsingManagedSNI())
{
return;
}

InternalConnectionWrapper wrapper = null;

using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
wrapper = new InternalConnectionWrapper(connection);

using (SqlCommand command = new SqlCommand("SELECT 5;", connection))
{
DataTestUtility.AssertEqualsWithDescription(5, command.ExecuteScalar(), "Incorrect scalar result.");
}

wrapper.KillConnection();
}

using (SqlConnection connection2 = new SqlConnection(connectionString))
{
connection2.Open();
Assert.False(wrapper.IsInternalConnectionOf(connection2), "New connection has internal connection that was just killed");
using (SqlCommand command = new SqlCommand("SELECT 5;", connection2))
{
DataTestUtility.AssertEqualsWithDescription(5, command.ExecuteScalar(), "Incorrect scalar result.");
}
}
}
#endif

/// <summary>
/// Tests if clearing all of the pools does actually remove the pools
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void ClearAllPoolsTest(string connectionString, bool marsAndAzureSynapse)
public static void ClearAllPoolsTest(string connectionString)
{
if (marsAndAzureSynapse)
{
return;
}

SqlConnection.ClearAllPools();
Assert.True(0 == ConnectionPoolWrapper.AllConnectionPools().Length, "Pools exist after clearing all pools");

Expand All @@ -196,13 +148,8 @@ public static void ClearAllPoolsTest(string connectionString, bool marsAndAzureS
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void ReclaimEmancipatedOnOpenTest(string connectionString, bool marsAndAzureSynapse)
public static void ReclaimEmancipatedOnOpenTest(string connectionString)
{
if (marsAndAzureSynapse)
{
return;
}

string newConnectionString = (new SqlConnectionStringBuilder(connectionString) { MaxPoolSize = 1 }).ConnectionString;
SqlConnection.ClearAllPools();

Expand All @@ -222,16 +169,39 @@ public static void ReclaimEmancipatedOnOpenTest(string connectionString, bool ma
}
}

#if DEBUG
/// <summary>
/// Tests if, when max pool size is reached, Open() will block until a connection becomes available
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void ReplacementConnectionUsesSemaphoreTest(string connectionString, bool marsAndAzureSynapse)
public static void MaxPoolWaitForConnectionTest(string connectionString)
{
if (marsAndAzureSynapse || !DataTestUtility.IsUsingManagedSNI())
{
return;
}
string newConnectionString = (new SqlConnectionStringBuilder(connectionString) { MaxPoolSize = 1 }).ConnectionString;
SqlConnection.ClearAllPools();

SqlConnection connection1 = new SqlConnection(newConnectionString);
connection1.Open();

InternalConnectionWrapper internalConnection = new InternalConnectionWrapper(connection1);
ConnectionPoolWrapper connectionPool = new ConnectionPoolWrapper(connection1);
ManualResetEventSlim taskAllowedToSpeak = new ManualResetEventSlim(false);

Task waitTask = Task.Factory.StartNew(() => MaxPoolWaitForConnectionTask(newConnectionString, internalConnection, connectionPool, taskAllowedToSpeak));
Thread.Sleep(200);
Assert.Equal(TaskStatus.Running, waitTask.Status);

connection1.Close();
taskAllowedToSpeak.Set();
waitTask.Wait();
Assert.Equal(TaskStatus.RanToCompletion, waitTask.Status);
}

#if DEBUG

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsUsingManagedSNI))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void ReplacementConnectionUsesSemaphoreTest(string connectionString)
{
string newConnectionString = (new SqlConnectionStringBuilder(connectionString) { MaxPoolSize = 2, ConnectTimeout = 5 }).ConnectionString;
SqlConnection.ClearAllPools();

Expand Down Expand Up @@ -293,21 +263,47 @@ public static void ReplacementConnectionUsesSemaphoreTest(string connectionStrin
waitAllTask.Wait();
Assert.True(taskWithLiveConnection && taskWithNewConnection && taskWithCorrectException, string.Format("Tasks didn't finish as expected.\nTask with live connection: {0}\nTask with new connection: {1}\nTask with correct exception: {2}\n", taskWithLiveConnection, taskWithNewConnection, taskWithCorrectException));
}
#endif

#if DEBUG
/// <summary>
/// Tests that cleanup removes connections that are unused for two cleanups
/// Tests if killing the connection using the InternalConnectionWrapper is working
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsUsingManagedSNI))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void CleanupTest(string connectionString, bool marsAndAzureSynapse)
public static void KillConnectionTest(string connectionString)
{
if (marsAndAzureSynapse || !DataTestUtility.IsUsingManagedSNI())
InternalConnectionWrapper wrapper = null;

using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
wrapper = new InternalConnectionWrapper(connection);

using (SqlCommand command = new SqlCommand("SELECT 5;", connection))
{
DataTestUtility.AssertEqualsWithDescription(5, command.ExecuteScalar(), "Incorrect scalar result.");
}

wrapper.KillConnection();
}

using (SqlConnection connection2 = new SqlConnection(connectionString))
{
return;
connection2.Open();
Assert.False(wrapper.IsInternalConnectionOf(connection2), "New connection has internal connection that was just killed");
using (SqlCommand command = new SqlCommand("SELECT 5;", connection2))
{
DataTestUtility.AssertEqualsWithDescription(5, command.ExecuteScalar(), "Incorrect scalar result.");
}
}
}

/// <summary>
/// Tests that cleanup removes connections that are unused for two cleanups
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsUsingManagedSNI))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void CleanupTest(string connectionString)
{
SqlConnection.ClearAllPools();

SqlConnection conn1 = new SqlConnection(connectionString);
Expand Down Expand Up @@ -343,50 +339,11 @@ public static void CleanupTest(string connectionString, bool marsAndAzureSynapse
connectionPool.Cleanup();
Assert.Equal(1, connectionPool.ConnectionCount);
}
#endif

/// <summary>
/// Tests if, when max pool size is reached, Open() will block until a connection becomes available
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsUsingManagedSNI))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void MaxPoolWaitForConnectionTest(string connectionString, bool marsAndAzureSynapse)
public static void ReplacementConnectionObeys0TimeoutTest(string connectionString)
{
if (marsAndAzureSynapse)
{
return;
}

string newConnectionString = (new SqlConnectionStringBuilder(connectionString) { MaxPoolSize = 1 }).ConnectionString;
SqlConnection.ClearAllPools();

SqlConnection connection1 = new SqlConnection(newConnectionString);
connection1.Open();

InternalConnectionWrapper internalConnection = new InternalConnectionWrapper(connection1);
ConnectionPoolWrapper connectionPool = new ConnectionPoolWrapper(connection1);
ManualResetEventSlim taskAllowedToSpeak = new ManualResetEventSlim(false);

Task waitTask = Task.Factory.StartNew(() => MaxPoolWaitForConnectionTask(newConnectionString, internalConnection, connectionPool, taskAllowedToSpeak));
Thread.Sleep(200);
Assert.Equal(TaskStatus.Running, waitTask.Status);

connection1.Close();
taskAllowedToSpeak.Set();
waitTask.Wait();
Assert.Equal(TaskStatus.RanToCompletion, waitTask.Status);
}

#if DEBUG
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void ReplacementConnectionObeys0TimeoutTest(string connectionString, bool marsAndAzureSynapse)
{
if (marsAndAzureSynapse || !DataTestUtility.IsUsingManagedSNI())
{
return;
}

string newConnectionString = (new SqlConnectionStringBuilder(connectionString) { ConnectTimeout = 0 }).ConnectionString;
SqlConnection.ClearAllPools();

Expand Down Expand Up @@ -430,13 +387,8 @@ public static void ReplacementConnectionObeys0TimeoutTest(string connectionStrin
/// </summary>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void TransactionPoolTest(string connectionString, bool marsAndAzureSynapse)
public static void TransactionPoolTest(string connectionString)
{
if (marsAndAzureSynapse)
{
return;
}

ConnectionPoolWrapper connectionPool = null;

using (TransactionScope transScope = new TransactionScope())
Expand Down Expand Up @@ -490,13 +442,8 @@ public static void TransactionPoolTest(string connectionString, bool marsAndAzur
/// <param name="connectionString"></param>
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ClassData(typeof(ConnectionPoolConnectionStringProvider))]
public static void TransactionCleanupTest(string connectionString, bool marsAndAzureSynapse)
public static void TransactionCleanupTest(string connectionString)
{
if (marsAndAzureSynapse)
{
return;
}

SqlConnection.ClearAllPools();
ConnectionPoolWrapper connectionPool = null;

Expand Down

0 comments on commit 68dcbb6

Please sign in to comment.