Skip to content

SNOW-2021012-first-round-cicd-tests-optimzation #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions Snowflake.Data.Tests/IcebergTests/TestIcebergTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ tx varchar(16777216),
ntz timestamp_ntz(6),
ltz timestamp_ltz(6),
bi binary(5),
ar array(number(10,0)),
ob object(a number(10,0), b varchar),
ar array(number(10,0)),
ob object(a number(10,0), b varchar),
ma map(varchar, varchar)";
private const string SqlCreateHybridTableColumns = @"id number(10,0) not null primary key,
nu number(10,0),
Expand Down Expand Up @@ -73,7 +73,7 @@ public TestIcebergTable(ResultFormat resultFormat)
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestInsertPlainText()
{
// Arrange
Expand All @@ -83,12 +83,12 @@ public void TestInsertPlainText()
SetResultFormat(conn);

// Act
conn.ExecuteNonQuery(@$"insert into {TableNameIceberg} ({SqlColumnsSimpleTypes})
values ({I32}, {I64}, {Dec}, {Dbl}, {Flt}, '{Txt}', {B1}, {B0},
'{_dt.ToString(FormatYmd)}',
'{_tm.ToString(FormatHms)}',
'{_ntz.ToString(FormatYmdHms)}',
'{_ltz.ToString(FormatYmdHmsfZ)}',
conn.ExecuteNonQuery(@$"insert into {TableNameIceberg} ({SqlColumnsSimpleTypes})
values ({I32}, {I64}, {Dec}, {Dbl}, {Flt}, '{Txt}', {B1}, {B0},
'{_dt.ToString(FormatYmd)}',
'{_tm.ToString(FormatHms)}',
'{_ntz.ToString(FormatYmdHms)}',
'{_ltz.ToString(FormatYmdHmsfZ)}',
'{ByteArrayToHexString(_bi)}')");

// Assert
Expand All @@ -105,7 +105,7 @@ public void TestInsertPlainText()


[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD tests")]
public void TestInsertWithValueBinding()
{
// Arrange
Expand All @@ -130,7 +130,7 @@ public void TestInsertWithValueBinding()
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestUpdateWithValueBinding()
{
// Arrange
Expand Down Expand Up @@ -188,7 +188,7 @@ public void TestUpdateWithValueBinding()
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestJoin()
{
using (var conn = OpenConnection())
Expand All @@ -201,9 +201,9 @@ public void TestJoin()
SetResultFormat(conn);

// Act
var sql = @$"select i.nu1,i.nu2,i.nu3,i.nu4,i.f,i.tx,i.bt,i.bf,i.dt,i.tm,i.ntz,i.ltz,i.bi, h.id,h.nu,h.tx2
from {TableNameIceberg} i
join {TableNameHybrid} h
var sql = @$"select i.nu1,i.nu2,i.nu3,i.nu4,i.f,i.tx,i.bt,i.bf,i.dt,i.tm,i.ntz,i.ltz,i.bi, h.id,h.nu,h.tx2
from {TableNameIceberg} i
join {TableNameHybrid} h
on i.nu1 = h.nu order by i.nu1";

// Assert
Expand Down Expand Up @@ -233,7 +233,7 @@ nu number(10,0),
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestDelete()
{
using (var conn = OpenConnection())
Expand All @@ -257,7 +257,7 @@ public void TestDelete()
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestDeleteAll()
{
using (var conn = OpenConnection())
Expand All @@ -280,7 +280,7 @@ public void TestDeleteAll()
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestMultiStatement()
{
using (var conn = OpenConnection())
Expand All @@ -307,7 +307,7 @@ public void TestMultiStatement()
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestBatchInsertForLargeData()
{
using (var conn = OpenConnection())
Expand Down Expand Up @@ -336,16 +336,16 @@ public void TestBatchInsertForLargeData()
}

[Test]
[Ignore("TODO: Enable when features available on the automated tests environment")]
[Ignore("Not a scope for CICD")]
public void TestStructuredTypesAsJsonString()
{
using (var conn = OpenConnection())
{
SetResultFormat(conn);
CreateIcebergTable(conn);
var sql = @$"insert into {TableNameIceberg} ({SqlColumnsStructureTypes})
select
[1,2,3]::ARRAY(number),
var sql = @$"insert into {TableNameIceberg} ({SqlColumnsStructureTypes})
select
[1,2,3]::ARRAY(number),
{{'a' : 1, 'b': 'two'}}::OBJECT(a number, b varchar),
{{'4':'one', '5': 'two', '6': 'three'}}::MAP(varchar, varchar)
";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Snowflake.Data.Client;
using Snowflake.Data.Core;
using Snowflake.Data.Core.Session;
using Snowflake.Data.Log;
using Snowflake.Data.Tests.Mock;
Expand Down Expand Up @@ -125,10 +125,10 @@ public async Task TestMinPoolSizeAsync()

// act
await connection.OpenAsync().ConfigureAwait(false);
Thread.Sleep(3000);

// assert
var pool = SnowflakeDbConnectionPool.GetPool(connection.ConnectionString);
Awaiter.WaitUntilConditionOrTimeout(() => pool.GetCurrentPoolSize() == 3, TimeSpan.FromMilliseconds(1000));
Assert.AreEqual(3, pool.GetCurrentPoolSize());

// cleanup
Expand Down Expand Up @@ -182,7 +182,7 @@ public void TestConcurrentConnectionPoolingAsync()
// add test case name in connection string to make in unique for each test case
// set short expiration timeout to cover the case that connection expired
string connStr = ConnectionString + ";application=TestConcurrentConnectionPoolingAsync2;ExpirationTimeout=3";
ConnectionSinglePoolCacheAsyncIT.ConcurrentPoolingAsyncHelper(connStr, true, 7, 100, 2);
ConnectionSinglePoolCacheAsyncIT.ConcurrentPoolingAsyncHelper(connStr, true, 5, 5, 3);
}

[Test(Description = "test connection pooling with concurrent connection and using async calls no close call for connection. Connection is closed when Dispose() is called by framework.")]
Expand All @@ -191,7 +191,7 @@ public void TestConcurrentConnectionPoolingDisposeAsync()
// add test case name in connection string to make in unique for each test case
// set short expiration timeout to cover the case that connection expired
string connStr = ConnectionString + ";application=TestConcurrentConnectionPoolingDisposeAsync2;ExpirationTimeout=3";
ConnectionSinglePoolCacheAsyncIT.ConcurrentPoolingAsyncHelper(connStr, false, 7, 100, 2);
ConnectionSinglePoolCacheAsyncIT.ConcurrentPoolingAsyncHelper(connStr, false, 5, 5, 3);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void TestWaitForTheIdleConnectionWhenExceedingMaxConnectionsLimitAsync()
}

[Test]
[Retry(2)]
[Retry(3)]
public void TestWaitInAQueueForAnIdleSession()
{
// arrange
Expand Down Expand Up @@ -321,7 +321,7 @@ public void TestNewConnectionPoolClean()
public void TestConnectionPoolExpirationWorks()
{
// arrange
const int ExpirationTimeoutInSeconds = 10;
const int ExpirationTimeoutInSeconds = 1;
var connectionString = ConnectionString + $"expirationTimeout={ExpirationTimeoutInSeconds};maxPoolSize=4;minPoolSize=2";
var pool = SnowflakeDbConnectionPool.GetPoolInternal(connectionString);
Assert.AreEqual(0, pool.GetCurrentPoolSize());
Expand Down Expand Up @@ -369,10 +369,10 @@ public void TestMinPoolSize()

// act
connection.Open();
Thread.Sleep(3000);

// assert
var pool = SnowflakeDbConnectionPool.GetPool(connection.ConnectionString);
Awaiter.WaitUntilConditionOrTimeout(() => pool.GetCurrentPoolSize() == 3, TimeSpan.FromMilliseconds(1000));
Assert.AreEqual(3, pool.GetCurrentPoolSize());

// cleanup
Expand Down Expand Up @@ -467,7 +467,11 @@ public void TestReturningCancelledSessionsToThePool([Values] bool cancelAsync)
}
}, CancellationToken.None);

Thread.Sleep(2000);
Awaiter.WaitUntilConditionOrTimeout(() =>
{
var state = pool.GetCurrentState();
return state.IdleSessionsCount == 0 && state.BusySessionsCount == 1;
}, TimeSpan.FromMilliseconds(1000));

// one busy session
Assert.AreEqual(0, pool.GetCurrentState().IdleSessionsCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ void ThreadProcess1(string connstr)
var conn1 = new SnowflakeDbConnection();
conn1.ConnectionString = connstr;
conn1.Open();
Thread.Sleep(1000);
conn1.Close();
Thread.Sleep(4000);
Thread.Sleep(1000);
Assert.AreEqual(ConnectionState.Closed, conn1.State);
}

Expand All @@ -80,7 +79,7 @@ void ThreadProcess2(string connstr)
conn1.ConnectionString = connstr;
conn1.Open();

Thread.Sleep(5000);
Thread.Sleep(1000);
SFStatement statement = new SFStatement(conn1.SfSession);
SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false, false);
Assert.AreEqual(true, resultSet.Next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public void TestConcurrentConnectionPoolingAsync()
{
// add test case name in connection string to make in unique for each test case
string connStr = ConnectionString + ";application=TestConcurrentConnectionPoolingAsync";
SnowflakeDbConnectionPool.SetMaxPoolSize(10);
SnowflakeDbConnectionPool.SetTimeout(3); // set short pooling timeout to cover the case that connection expired
ConcurrentPoolingAsyncHelper(connStr, true, 12, 100, 100);
SnowflakeDbConnectionPool.SetMaxPoolSize(3);
SnowflakeDbConnectionPool.SetTimeout(1); // set short pooling timeout to cover the case that connection expired
ConcurrentPoolingAsyncHelper(connStr, true, 5, 5, 3);
SnowflakeDbConnectionPool.SetTimeout(3600);
}

Expand All @@ -139,9 +139,9 @@ public void TestConcurrentConnectionPoolingDisposeAsync()
{
// add test case name in connection string to make in unique for each test case
string connStr = ConnectionString + ";application=TestConcurrentConnectionPoolingDisposeAsync";
SnowflakeDbConnectionPool.SetMaxPoolSize(10);
SnowflakeDbConnectionPool.SetTimeout(3); // set short pooling timeout to cover the case that connection expired
ConcurrentPoolingAsyncHelper(connStr, false, 12, 100, 100);
SnowflakeDbConnectionPool.SetMaxPoolSize(3);
SnowflakeDbConnectionPool.SetTimeout(1); // set short pooling timeout to cover the case that connection expired
ConcurrentPoolingAsyncHelper(connStr, false, 5, 5, 3);
SnowflakeDbConnectionPool.SetTimeout(3600);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void TestBasicConnectionPool()
public void TestConcurrentConnectionPooling()
{
// add test case name in connection string to make in unique for each test case
string connStr = ConnectionString + ";application=TestConcurrentConnectionPooling";
string connStr = ConnectionString + ";application=TestConcurrentConnectionPooling;";
SnowflakeDbConnectionPool.SetMaxPoolSize(2);
ConcurrentPoolingHelper(connStr, true);
}

Expand All @@ -67,21 +68,22 @@ public void TestConcurrentConnectionPooling()
public void TestConcurrentConnectionPoolingDispose()
{
// add test case name in connection string to make in unique for each test case
string connStr = ConnectionString + ";application=TestConcurrentConnectionPoolingNoClose";
string connStr = ConnectionString + ";application=TestConcurrentConnectionPoolingNoClose;";
SnowflakeDbConnectionPool.SetMaxPoolSize(2);
ConcurrentPoolingHelper(connStr, false);
}

static void ConcurrentPoolingHelper(string connectionString, bool closeConnection)
{
// thread number a bit larger than pool size so some connections
// would fail on pooling while some connections could success
const int ThreadNum = 12;
const int ThreadNum = 3;
// set short pooling timeout to cover the case that connection expired
const int PoolTimeout = 3;
const int PoolTimeout = 1;

// reset to default settings in case it changed by other test cases
Assert.AreEqual(true, SnowflakeDbConnectionPool.GetPool(connectionString).GetPooling()); // to instantiate pool
SnowflakeDbConnectionPool.SetMaxPoolSize(10);
SnowflakeDbConnectionPool.SetMaxPoolSize(2);
SnowflakeDbConnectionPool.SetTimeout(PoolTimeout);

var threads = new Task[ThreadNum];
Expand All @@ -98,7 +100,7 @@ static void ConcurrentPoolingHelper(string connectionString, bool closeConnectio
// thead to execute query with new connection in a loop
static void QueryExecutionThread(string connectionString, bool closeConnection)
{
for (int i = 0; i < 100; i++)
for (int i = 0; i < 10; i++)
{
using (DbConnection conn = new SnowflakeDbConnection(connectionString))
{
Expand Down Expand Up @@ -347,8 +349,8 @@ public void TestReleaseConnectionWhenRollbackFails()
public void TestCloseSessionAfterTimeout()
{
// arrange
const int SessionTimeoutSeconds = 2;
const int TimeForBackgroundSessionCloseMillis = 2000;
const int SessionTimeoutSeconds = 1;
const int TimeForBackgroundSessionCloseMillis = 1000;
SnowflakeDbConnectionPool.SetTimeout(SessionTimeoutSeconds);
var conn1 = new SnowflakeDbConnection(ConnectionString);
conn1.Open();
Expand All @@ -360,7 +362,8 @@ public void TestCloseSessionAfterTimeout()

// act
conn2.Open(); // it gets a session from the caching pool firstly closing session of conn1 in background
Thread.Sleep(TimeForBackgroundSessionCloseMillis); // wait for closing expired session

Awaiter.WaitUntilConditionOrTimeout(() => !session.IsEstablished(), TimeSpan.FromMilliseconds(TimeForBackgroundSessionCloseMillis));

// assert
Assert.IsFalse(session.IsEstablished());
Expand Down
Loading