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 0a576cf
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ public SqlExponentialIntervalEnumerator(TimeSpan deltaBackoffTime, TimeSpan maxT

protected override TimeSpan GetNextInterval()
{
var random = new Random();
int delta = Convert.ToInt32((Math.Pow(2.0, internalCounter++) - 1.0)
* random.Next(Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 0.8), Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 1.2)));
var newVlaue = TimeSpan.FromMilliseconds(MinTimeInterval.TotalMilliseconds + delta);
return newVlaue < MaxTimeInterval ? newVlaue : MaxTimeInterval;
if (Current >= MaxTimeInterval)
{
return MaxTimeInterval;
}
else
{
var random = new Random();
var maxRandom = GapTimeInterval.TotalMilliseconds * 1.2 < int.MaxValue ? Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 1.2) : int.MaxValue;
var minRandom = GapTimeInterval.TotalMilliseconds * 0.8 < int.MaxValue ? Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 0.8) : Convert.ToInt32(int.MaxValue * 0.6);
var delta = (Math.Pow(2.0, internalCounter++) - 1.0) * random.Next(minRandom, maxRandom);
var newVlaue = TimeSpan.FromMilliseconds(MinTimeInterval.TotalMilliseconds + delta);
return newVlaue < MaxTimeInterval ? newVlaue : MaxTimeInterval;
}
}
}

Expand All @@ -41,8 +49,9 @@ protected override TimeSpan GetNextInterval()
else
{
var random = new Random();
var interval = TimeSpan.FromMilliseconds(Current.TotalMilliseconds
+ random.Next(Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 0.8), Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 1.2)));
var maxRandom = GapTimeInterval.TotalMilliseconds * 1.2 < int.MaxValue ? Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 1.2) : int.MaxValue;
var minRandom = GapTimeInterval.TotalMilliseconds * 0.8 < int.MaxValue ? Convert.ToInt32(GapTimeInterval.TotalMilliseconds * 0.8) : Convert.ToInt32(int.MaxValue * 0.6);
var interval = TimeSpan.FromMilliseconds(Current.TotalMilliseconds + random.Next(minRandom, maxRandom));

if (interval < MinTimeInterval)
{
Expand Down
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
Loading

0 comments on commit 0a576cf

Please sign in to comment.