Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavoudEshtehari committed Oct 15, 2020
1 parent 8c6d8f8 commit 63e7dc3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ public static void DropStoredProcedure(SqlConnection sqlConnection, string spNam

public static void DropDatabase(SqlConnection sqlConnection, string dbName)
{
using (SqlCommand cmd = new SqlCommand(string.Format("IF (DB_ID('{0}') IS NOT NULL) \nBEGIN \n ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE \n DROP DATABASE {0} \nEND", dbName), sqlConnection))
// database name must be pass without brackets.
using (SqlCommand cmd = new SqlCommand(string.Format("IF (DB_ID('{0}') IS NOT NULL) \nBEGIN \n ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE \n DROP DATABASE [{0}] \nEND", dbName), sqlConnection))
{
cmd.ExecuteNonQuery();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static IEnumerable<object[]> GetConnectionStrings()
{
builder.Clear();
builder.ConnectionString = cnnString;
builder.ConnectTimeout = 1;
builder.ConnectTimeout = 5;
builder.Pooling = false;
yield return new object[] { builder.ConnectionString };

Expand Down Expand Up @@ -105,13 +105,13 @@ public static IEnumerable<object[]> GetConnectionAndRetryStrategyFilterDMLStatem

public static IEnumerable<object[]> GetConnectionAndRetryStrategyLongRunner(int numberOfRetries)
{
return GetConnectionAndRetryStrategy(numberOfRetries, TimeSpan.FromSeconds(30), FilterSqlStatements.None, null, 5 * 1000 );
return GetConnectionAndRetryStrategy(numberOfRetries, TimeSpan.FromSeconds(60), FilterSqlStatements.None, null, 10 * 1000 );
}

// 3702: Cannot drop database because it is currently in use.
public static IEnumerable<object[]> GetConnectionAndRetryStrategyErr3702(int numberOfRetries)
{
return GetConnectionAndRetryStrategy(numberOfRetries, TimeSpan.FromMilliseconds(100), FilterSqlStatements.None, new int[] { 3702 });
return GetConnectionAndRetryStrategy(numberOfRetries, TimeSpan.FromMilliseconds(2000), FilterSqlStatements.None, new int[] { 3702 }, 500);
}

// -2: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void RetryExecuteUnauthorizedSqlStatementDML(string cnnString, SqlRetryLo
}

[Theory]
[MemberData(nameof(RetryLogicTestHelper.GetConnectionAndRetryStrategyErr3702), parameters: new object[] { 2 }, MemberType = typeof(RetryLogicTestHelper))]
[MemberData(nameof(RetryLogicTestHelper.GetConnectionAndRetryStrategyErr3702), parameters: new object[] { 5 }, MemberType = typeof(RetryLogicTestHelper))]
public void DropDatabaseWithActiveConnection(string cnnString, SqlRetryLogicBaseProvider provider)
{
string database = DataTestUtility.GetUniqueNameForSqlServer($"RetryLogic_{provider.RetryLogic.RetryIntervalEnumerator.GetType().Name}", false);
Expand All @@ -208,7 +208,7 @@ public void DropDatabaseWithActiveConnection(string cnnString, SqlRetryLogicBase
{
cnn1.Open();
cmd.Connection = cnn1;
cmd.CommandText = $"CREATE DATABASE {database}";
cmd.CommandText = $"CREATE DATABASE [{database}]";
cmd.ExecuteNonQuery();

// open an active connection to the database to raise error 3702 if someone drops it.
Expand All @@ -224,7 +224,7 @@ public void DropDatabaseWithActiveConnection(string cnnString, SqlRetryLogicBase

// drop the database
cmd.RetryLogicProvider = provider;
cmd.CommandText = $"DROP DATABASE {database}";
cmd.CommandText = $"DROP DATABASE [{database}]";
cmd.ExecuteNonQuery();

Assert.True(provider.RetryLogic.Current > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void CreateDatabaseWhenTryToConnect(string cnnString, SqlRetryLogicBasePr
ConnectTimeout = 1
};

using (var cnn1 = new SqlConnection(new SqlConnectionStringBuilder(cnnString) { ConnectTimeout = 30 }.ConnectionString))
using (var cnn1 = new SqlConnection(new SqlConnectionStringBuilder(cnnString) { ConnectTimeout = 60 }.ConnectionString))
{
cnn1.Open();
provider.Retrying += (object s, SqlRetryingEventArgs e) =>
Expand All @@ -56,7 +56,7 @@ public void CreateDatabaseWhenTryToConnect(string cnnString, SqlRetryLogicBasePr
// Create database just after first faliure.
if (e.RetryCount == 0)
{
cmd.CommandText = $"CREATE DATABASE {database};";
cmd.CommandText = $"CREATE DATABASE [{database}];";
cmd.ExecuteNonQueryAsync();
}
}
Expand Down

0 comments on commit 63e7dc3

Please sign in to comment.