Skip to content

Commit

Permalink
Use different sessions for the test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Mar 20, 2024
1 parent b9a58a3 commit 912f4a2
Showing 1 changed file with 66 additions and 90 deletions.
156 changes: 66 additions & 90 deletions Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,68 +219,56 @@ public async Task TestExecuteNormalQueryWhileAsyncExecQueryIsRunningAsync()
string queryId;
var expectedWaitTime = 5;

// Start the async exec query
using (SnowflakeDbConnection conn = new SnowflakeDbConnection())
SnowflakeDbConnection[] connections = new SnowflakeDbConnection[3];
for (int i = 0; i < connections.Length; i++)
{
conn.ConnectionString = ConnectionString;
await conn.OpenAsync(CancellationToken.None).ConfigureAwait(false);

using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand())
{
// Arrange
cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');";
connections[i] = new SnowflakeDbConnection(ConnectionString);
await connections[i].OpenAsync(CancellationToken.None).ConfigureAwait(false);
}

// Act
queryId = await cmd.ExecuteAsyncInAsyncMode(CancellationToken.None).ConfigureAwait(false);
var queryStatus = await cmd.GetQueryStatusAsync(queryId, CancellationToken.None).ConfigureAwait(false);
// Start the async exec query
using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)connections[0].CreateCommand())
{
// Arrange
cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');";

// Assert
Assert.IsTrue(QueryStatuses.IsStillRunning(queryStatus));
}
// Act
queryId = await cmd.ExecuteAsyncInAsyncMode(CancellationToken.None).ConfigureAwait(false);
var queryStatus = await cmd.GetQueryStatusAsync(queryId, CancellationToken.None).ConfigureAwait(false);

await conn.CloseAsync(CancellationToken.None).ConfigureAwait(false);
// Assert
Assert.IsTrue(QueryStatuses.IsStillRunning(queryStatus));
}

// Execute a normal query
using (SnowflakeDbConnection conn = new SnowflakeDbConnection())
using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)connections[1].CreateCommand())
{
conn.ConnectionString = ConnectionString;
conn.Open();

using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand())
{
// Arrange
cmd.CommandText = $"select 1;";

// Act
var row = cmd.ExecuteScalar();
// Arrange
cmd.CommandText = $"select 1;";

// Assert
Assert.AreEqual(1, row);
}
// Act
var row = cmd.ExecuteScalar();

conn.Close();
// Assert
Assert.AreEqual(1, row);
}

// Get results of the async exec query
using (SnowflakeDbConnection conn = new SnowflakeDbConnection())
using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)connections[2].CreateCommand())
{
conn.ConnectionString = ConnectionString;
await conn.OpenAsync(CancellationToken.None).ConfigureAwait(false);

using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand())
{
// Act
var reader = await cmd.GetResultsFromQueryIdAsync(queryId, CancellationToken.None).ConfigureAwait(false);
var queryStatus = await cmd.GetQueryStatusAsync(queryId, CancellationToken.None).ConfigureAwait(false);
// Act
var reader = await cmd.GetResultsFromQueryIdAsync(queryId, CancellationToken.None).ConfigureAwait(false);
var queryStatus = await cmd.GetQueryStatusAsync(queryId, CancellationToken.None).ConfigureAwait(false);

// Assert
Assert.IsTrue(reader.Read());
Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0));
Assert.AreEqual(QueryStatus.Success, queryStatus);
}
// Assert
Assert.IsTrue(reader.Read());
Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0));
Assert.AreEqual(QueryStatus.Success, queryStatus);
}

await conn.CloseAsync(CancellationToken.None).ConfigureAwait(false);
for (int i = 0; i < connections.Length; i++)
{
await connections[i].CloseAsync(CancellationToken.None).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -1367,66 +1355,54 @@ public void TestExecuteNormalQueryWhileAsyncExecQueryIsRunning()
string queryId;
var expectedWaitTime = 5;

// Start the async exec query
using (SnowflakeDbConnection conn = new SnowflakeDbConnection())
SnowflakeDbConnection[] connections = new SnowflakeDbConnection[3];
for (int i = 0; i < connections.Length; i++)
{
conn.ConnectionString = ConnectionString;
conn.Open();

using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand())
{
// Arrange
cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');";
connections[i] = new SnowflakeDbConnection(ConnectionString);
connections[i].Open();
}

// Act
queryId = cmd.ExecuteInAsyncMode();
// Start the async exec query
using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)connections[0].CreateCommand())
{
// Arrange
cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');";

// Assert
Assert.IsTrue(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryId)));
}
// Act
queryId = cmd.ExecuteInAsyncMode();

conn.Close();
// Assert
Assert.IsTrue(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryId)));
}

// Execute a normal query
using (SnowflakeDbConnection conn = new SnowflakeDbConnection())
using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)connections[1].CreateCommand())
{
conn.ConnectionString = ConnectionString;
conn.Open();
// Arrange
cmd.CommandText = $"select 1;";

using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand())
{
// Arrange
cmd.CommandText = $"select 1;";
// Act
var row = cmd.ExecuteScalar();

// Act
var row = cmd.ExecuteScalar();

// Assert
Assert.AreEqual(1, row);
}

conn.Close();
// Assert
Assert.AreEqual(1, row);
}

// Get results of the async exec query
using (SnowflakeDbConnection conn = new SnowflakeDbConnection())
using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)connections[2].CreateCommand())
{
conn.ConnectionString = ConnectionString;
conn.Open();
// Act
DbDataReader reader = cmd.GetResultsFromQueryId(queryId);

using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand())
{
// Act
DbDataReader reader = cmd.GetResultsFromQueryId(queryId);

// Assert
Assert.IsTrue(reader.Read());
Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0));
Assert.AreEqual(QueryStatus.Success, cmd.GetQueryStatus(queryId));
}
// Assert
Assert.IsTrue(reader.Read());
Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0));
Assert.AreEqual(QueryStatus.Success, cmd.GetQueryStatus(queryId));
}

conn.Close();
for (int i = 0; i < connections.Length; i++)
{
connections[i].Close();
}
}

Expand Down

0 comments on commit 912f4a2

Please sign in to comment.