Skip to content

Commit

Permalink
Fixes to flaky tests which fail due to mocked connections coming back…
Browse files Browse the repository at this point in the history
… to the connection pool
  • Loading branch information
sfc-gh-mhofman committed Oct 10, 2023
1 parent 1962320 commit 4eae0c5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
3 changes: 0 additions & 3 deletions Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ public void TestSimpleLargeResultSet()
}


/*
* Disabled to make sure that configuration changes does not cause problems with appveyor
*/
[Test, NonParallelizable]
public void TestUseV1ResultParser()
{
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/Mock/MockRetryUntilRestTimeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
string sid = "")
{
// Override the http timeout and set to 1ms to force all http request to timeout and retry
message.Properties[BaseRestRequest.HTTP_REQUEST_TIMEOUT_KEY] = TimeSpan.FromMilliseconds(1);
message.Properties[BaseRestRequest.HTTP_REQUEST_TIMEOUT_KEY] = TimeSpan.FromTicks(0);
return await (base.SendAsync(message, restTimeout, externalCancellationToken).ConfigureAwait(false));
}
}
Expand Down
5 changes: 5 additions & 0 deletions Snowflake.Data.Tests/Mock/MockSnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,10 @@ private void OnSessionEstablished()
{
_connectionState = ConnectionState.Open;
}

protected override bool CanReuseSession(TransactionRollbackStatus transactionRollbackStatus)
{
return false;
}
}
}
4 changes: 2 additions & 2 deletions Snowflake.Data/Client/SnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SnowflakeDbConnection : DbConnection
// Will fix that in a separated PR though as it's a different issue
private static Boolean _isArrayBindStageCreated;

private enum TransactionRollbackStatus
protected enum TransactionRollbackStatus
{
Undefined, // used to indicate ignored transaction status when pool disabled
Success,
Expand Down Expand Up @@ -232,7 +232,7 @@ public Task CloseAsync(CancellationToken cancellationToken)
return taskCompletionSource.Task;
}

private bool CanReuseSession(TransactionRollbackStatus transactionRollbackStatus)
protected virtual bool CanReuseSession(TransactionRollbackStatus transactionRollbackStatus)
{
return SnowflakeDbConnectionPool.GetPooling() &&
transactionRollbackStatus == TransactionRollbackStatus.Success;
Expand Down
5 changes: 4 additions & 1 deletion Snowflake.Data/Core/HttpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
if (!httpTimeout.Equals(Timeout.InfiniteTimeSpan))
{
childCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
childCts.CancelAfter(httpTimeout);
if (httpTimeout.Ticks == 0)
childCts.Cancel();
else
childCts.CancelAfter(httpTimeout);
}
response = await base.SendAsync(requestMessage, childCts == null ?
cancellationToken : childCts.Token).ConfigureAwait(false);
Expand Down

0 comments on commit 4eae0c5

Please sign in to comment.