Skip to content
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

SNOW-902588: Tests parallelization #772

Merged
merged 28 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
898295b
Enable parallelization
sfc-gh-pbulawa Sep 4, 2023
53a6df1
Set test to be non-parallelizable
sfc-gh-pbulawa Sep 4, 2023
b692548
Add non-parallelizable for the tests using global config
sfc-gh-pbulawa Sep 4, 2023
b9ecf30
Revert the schema at the end of the test
sfc-gh-pbulawa Sep 4, 2023
c6e8c89
Set LevelOfParallelism parameter
sfc-gh-pbulawa Sep 5, 2023
107d3c8
Change LevelOfParallelism
sfc-gh-pbulawa Sep 5, 2023
cbc7bb6
Clear pools after tests
sfc-gh-pbulawa Sep 5, 2023
7703264
Fix multithreading test
sfc-gh-pbulawa Sep 5, 2023
3f5c32e
Clear pools after connection pool tests
sfc-gh-pbulawa Sep 5, 2023
ef31891
Set static for OneTimeTearDown
sfc-gh-pbulawa Sep 5, 2023
9766ef5
Remove unnecessary cancellation tokens
sfc-gh-pbulawa Sep 5, 2023
6736423
Add cancellation token as it is required by .NET Framework
sfc-gh-pbulawa Sep 5, 2023
88ec232
Set cancellation token for CloseAsync
sfc-gh-pbulawa Sep 5, 2023
95d85ec
Remove NonParallelizable
sfc-gh-pbulawa Sep 5, 2023
cbd42ef
Add NonParallelizable attribute for each test using MockSnowflakeDbCo…
sfc-gh-pbulawa Sep 6, 2023
3ba13c5
Merge remote-tracking branch 'origin/master' into SNOW-902588-test-pa…
sfc-gh-pbulawa Sep 6, 2023
98f12c5
Remove unnecessary clear pools
sfc-gh-pbulawa Sep 6, 2023
0c9102e
Add one more test as non-parallelizable
sfc-gh-pbulawa Sep 6, 2023
8f0c683
Test output test
sfc-gh-pbulawa Sep 6, 2023
b672918
Fix test
sfc-gh-pbulawa Sep 6, 2023
2e67998
Merge remote-tracking branch 'origin/master' into SNOW-902588-test-pa…
sfc-gh-pbulawa Sep 11, 2023
bcc8327
Change TableName to TestNameWithWorker and use it in mocked client tests
sfc-gh-pbulawa Sep 11, 2023
97f2d59
Test sequential run parameter
sfc-gh-pbulawa Sep 11, 2023
82c8d09
Comment the sequential env
sfc-gh-pbulawa Sep 11, 2023
2207dfb
Remove debug print
sfc-gh-pbulawa Sep 11, 2023
d1ff11c
Remove log
sfc-gh-pbulawa Sep 11, 2023
7989747
Remove unnecessary assignment
sfc-gh-pbulawa Sep 11, 2023
986f630
Add new var
sfc-gh-pbulawa Sep 11, 2023
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ concurrency:
env:
DOTNET_VERSION: 6.0
DOTNET_LEGACY_VERSION: 4.7.1
# uncomment to run the tests sequentially
#SEQUENTIAL_ENV: SEQUENTIAL_TEST_RUN

jobs:
test-windows:
Expand Down
40 changes: 20 additions & 20 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ public void TestConnectString()
//cmd.CommandText = "drop database \"dlTest\"";
cmd.CommandText = $"drop schema \"{schemaName}\"";
cmd.ExecuteNonQuery();
cmd.CommandText = "use database "+ testConfig.database;
cmd.CommandText = "use database " + testConfig.database;
cmd.ExecuteNonQuery();
cmd.CommandText = "use schema " + testConfig.schema;
cmd.ExecuteNonQuery();
}
conn.Close();
Expand Down Expand Up @@ -379,7 +381,7 @@ public void TestConnectViaSecureString()
}
}

[Test]
[Test, NonParallelizable]
public void TestLoginTimeout()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand Down Expand Up @@ -417,7 +419,7 @@ public void TestLoginTimeout()
}
}

[Test]
[Test, NonParallelizable]
public void TestLoginWithMaxRetryReached()
{
using (IDbConnection conn = new MockSnowflakeDbConnection())
Expand Down Expand Up @@ -445,7 +447,7 @@ public void TestLoginWithMaxRetryReached()
}
}

[Test]
[Test, NonParallelizable]
[Ignore("Disable unstable test cases for now")]
public void TestDefaultLoginTimeout()
{
Expand Down Expand Up @@ -638,6 +640,7 @@ public void TestSwitchDb()
Assert.AreEqual("SNOWFLAKE_SAMPLE_DATA", conn.Database);
}

conn.ChangeDatabase(testConfig.database);
conn.Close();
}

Expand Down Expand Up @@ -1666,7 +1669,7 @@ class SFConnectionITAsync : SFBaseTestAsync
private static SFLogger logger = SFLoggerFactory.GetLogger<SFConnectionITAsync>();


[Test]
[Test, NonParallelizable]
public void TestCancelLoginBeforeTimeout()
{
using (var conn = new MockSnowflakeDbConnection())
Expand Down Expand Up @@ -1714,7 +1717,7 @@ public void TestCancelLoginBeforeTimeout()
}
}

[Test]
[Test, NonParallelizable]
public void TestAsyncLoginTimeout()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Expand All @@ -1728,11 +1731,10 @@ public void TestAsyncLoginTimeout()

Assert.AreEqual(conn.State, ConnectionState.Closed);

CancellationTokenSource connectionCancelToken = new CancellationTokenSource();
Stopwatch stopwatch = Stopwatch.StartNew();
try
{
Task connectTask = conn.OpenAsync(connectionCancelToken.Token);
Task connectTask = conn.OpenAsync(CancellationToken.None);
connectTask.Wait();
}
catch (AggregateException e)
Expand All @@ -1755,7 +1757,7 @@ public void TestAsyncLoginTimeout()
}
}

[Test]
[Test, NonParallelizable]
public void TestAsyncDefaultLoginTimeout()
{
using (var conn = new MockSnowflakeDbConnection())
Expand All @@ -1765,11 +1767,10 @@ public void TestAsyncDefaultLoginTimeout()

Assert.AreEqual(conn.State, ConnectionState.Closed);

CancellationTokenSource connectionCancelToken = new CancellationTokenSource();
Stopwatch stopwatch = Stopwatch.StartNew();
try
{
Task connectTask = conn.OpenAsync(connectionCancelToken.Token);
Task connectTask = conn.OpenAsync(CancellationToken.None);
connectTask.Wait();
}
catch (AggregateException e)
Expand Down Expand Up @@ -1802,11 +1803,10 @@ public void TestAsyncConnectionFailFast()
conn.ConnectionString = invalidConnectionString;

Assert.AreEqual(conn.State, ConnectionState.Closed);
CancellationTokenSource connectionCancelToken = new CancellationTokenSource();
Task connectTask = null;
try
{
connectTask = conn.OpenAsync(connectionCancelToken.Token);
connectTask = conn.OpenAsync(CancellationToken.None);
connectTask.Wait();
Assert.Fail();
}
Expand Down Expand Up @@ -1835,22 +1835,22 @@ public void TestCloseAsyncWithCancellation()
Task task = null;

// Close the connection. It's not opened yet, but it should not have any issue
task = conn.CloseAsync(new CancellationTokenSource().Token);
task = conn.CloseAsync(CancellationToken.None);
task.Wait();
Assert.AreEqual(conn.State, ConnectionState.Closed);

// Open the connection
task = conn.OpenAsync(new CancellationTokenSource().Token);
task = conn.OpenAsync(CancellationToken.None);
task.Wait();
Assert.AreEqual(conn.State, ConnectionState.Open);

// Close the opened connection
task = conn.CloseAsync(new CancellationTokenSource().Token);
task = conn.CloseAsync(CancellationToken.None);
task.Wait();
Assert.AreEqual(conn.State, ConnectionState.Closed);

// Close the connection again.
task = conn.CloseAsync(new CancellationTokenSource().Token);
task = conn.CloseAsync(CancellationToken.None);
task.Wait();
Assert.AreEqual(conn.State, ConnectionState.Closed);
}
Expand Down Expand Up @@ -1893,7 +1893,7 @@ public void TestCloseAsync()
}
#endif

[Test]
[Test, NonParallelizable]
public void TestCloseAsyncFailure()
{
using (var conn = new MockSnowflakeDbConnection(new MockCloseSessionException()))
Expand All @@ -1904,12 +1904,12 @@ public void TestCloseAsyncFailure()
Task task = null;

// Open the connection
task = conn.OpenAsync(new CancellationTokenSource().Token);
task = conn.OpenAsync(CancellationToken.None);
task.Wait();
Assert.AreEqual(conn.State, ConnectionState.Open);

// Close the opened connection
task = conn.CloseAsync(new CancellationTokenSource().Token);
task = conn.CloseAsync(CancellationToken.None);
try
{
task.Wait();
Expand Down
21 changes: 18 additions & 3 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public void AfterTest()
previousPoolConfig.Reset();
}

[OneTimeTearDown]
public static void AfterAllTests()
{
SnowflakeDbConnectionPool.ClearAllPools();
}

[Test]
[Ignore("dummy test case for showing test progress.")]
public void ConnectionPoolTDone()
Expand Down Expand Up @@ -339,9 +345,12 @@ public void TestConnectionPoolMultiThreading()

t1.Start();
t2.Start();

t1.Join();
t2.Join();
}

static void ThreadProcess1(string connstr)
void ThreadProcess1(string connstr)
{
var conn1 = new SnowflakeDbConnection();
conn1.ConnectionString = connstr;
Expand All @@ -352,7 +361,7 @@ static void ThreadProcess1(string connstr)
Assert.AreEqual(ConnectionState.Closed, conn1.State);
}

static void ThreadProcess2(string connstr)
void ThreadProcess2(string connstr)
{
var conn1 = new SnowflakeDbConnection();
conn1.ConnectionString = connstr;
Expand Down Expand Up @@ -429,7 +438,7 @@ public void TestConnectionPoolTurnOff()
}
}

[TestFixture]
[TestFixture, NonParallelizable]
class SFConnectionPoolITAsync : SFBaseTestAsync
{
private static SFLogger logger = SFLoggerFactory.GetLogger<SFConnectionPoolITAsync>();
Expand All @@ -448,6 +457,12 @@ public void AfterTest()
{
previousPoolConfig.Reset();
}

[OneTimeTearDown]
public static void AfterAllTests()
{
SnowflakeDbConnectionPool.ClearAllPools();
}

[Test]
public void TestConnectionPoolWithAsync()
Expand Down
8 changes: 3 additions & 5 deletions Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ public void DbCommandITAsyncDone()
[Test]
public void TestExecAsyncAPI()
{
SnowflakeDbConnectionPool.ClearAllPools();
using (DbConnection conn = new SnowflakeDbConnection())
{
SnowflakeDbConnectionPool.ClearAllPools();
conn.ConnectionString = ConnectionString;

Task connectTask = conn.OpenAsync(CancellationToken.None);
Assert.AreEqual(ConnectionState.Connecting, conn.State);

connectTask.Wait();
Assert.AreEqual(ConnectionState.Open, conn.State);

Expand Down Expand Up @@ -254,7 +252,7 @@ public void TestSimpleLargeResultSet()
/*
* Disabled to make sure that configuration changes does not cause problems with appveyor
*/
[Test]
[Test, NonParallelizable]
public void TestUseV1ResultParser()
{
var chunkParserVersion = SFConfiguration.Instance().ChunkParserVersion;
Expand Down Expand Up @@ -283,7 +281,7 @@ public void TestUseV1ResultParser()
SFConfiguration.Instance().ChunkDownloaderVersion = chunkDownloaderVersion;
}

[Test]
[Test, NonParallelizable]
public void TestUseV2ChunkDownloader()
{
var chunkParserVersion = SFConfiguration.Instance().ChunkParserVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void testWithAllQueryTypes()
$"remove @%{TableName};" +
"create or replace temporary procedure P1() returns varchar language javascript as $$ return ''; $$;" +
"call p1();" +
"use role public";
$"use role {testConfig.role}";

// Set statement count
var stmtCountParam = cmd.CreateParameter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Snowflake.Data.Tests.IntegrationTests
using Client;
using System.Threading.Tasks;

[TestFixture]
[TestFixture, NonParallelizable]
class SFReusableChunkTest : SFBaseTest
{
[Test]
Expand Down
18 changes: 15 additions & 3 deletions Snowflake.Data.Tests/SFBaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using NUnit.Framework;
using Snowflake.Data.Client;
using Snowflake.Data.Tests.Util;

[assembly:LevelOfParallelism(10)]

namespace Snowflake.Data.Tests
{
using NUnit.Framework;
Expand Down Expand Up @@ -48,14 +51,18 @@ public static void TearDownContext()
[TestFixture]
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
[SetCulture("en-US")]
#if !SEQUENTIAL_TEST_RUN
[Parallelizable(ParallelScope.All)]
#endif
public class SFBaseTestAsync
{
private const string ConnectionStringWithoutAuthFmt = "scheme={0};host={1};port={2};" +
"account={3};role={4};db={5};schema={6};warehouse={7}";
private const string ConnectionStringSnowflakeAuthFmt = ";user={0};password={1};";
protected readonly string TestName = TestContext.CurrentContext.Test.MethodName;

protected string TableName => TestName + TestContext.CurrentContext.WorkerId?.Replace("#", "_");
protected string TestNameWithWorker => TestName + TestContext.CurrentContext.WorkerId?.Replace("#", "_");
protected string TableName => TestNameWithWorker;


private Stopwatch _stopwatch;

Expand Down Expand Up @@ -151,9 +158,14 @@ public class TestEnvironment

private static Dictionary<string, TimeSpan> s_testPerformance;

private static readonly object s_testPerformanceLock = new object();

public static void RecordTestPerformance(string name, TimeSpan time)
{
s_testPerformance.Add(name, time);
lock (s_testPerformanceLock)
{
s_testPerformance.Add(name, time);
}
}

[OneTimeSetUp]
Expand Down
1 change: 1 addition & 0 deletions Snowflake.Data.Tests/Snowflake.Data.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Copyright>Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.</Copyright>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>7.3</LangVersion>
<DefineConstants>$(SEQUENTIAL_ENV)</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private SFResultSet mockSFResultSet(QueryExecResponseData responseData, Cancella
return new SFResultSet(responseData, new SFStatement(session), token);
}

[Test]
[Test, NonParallelizable]
public void TestGetDownloader([Values(false, true)] bool useV2ChunkDownloader, [Values(1, 2, 3, 4)] int chunkDownloaderVersion)
{
// Set configuration settings
Expand Down
10 changes: 7 additions & 3 deletions Snowflake.Data.Tests/UnitTests/SFAzureClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

using System;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
Expand Down Expand Up @@ -45,7 +47,7 @@ class SFAzureClientTest : SFBaseTest
const int Parallel = 0;

// File name for download tests
const string DownloadFileName = "mockFileName.txt";
[ThreadStatic] private static string t_downloadFileName;

// Token for async tests
CancellationToken _cancellationToken;
Expand All @@ -60,6 +62,8 @@ class SFAzureClientTest : SFBaseTest
[SetUp]
public void BeforeTest()
{
t_downloadFileName = TestNameWithWorker + "_mockFileName.txt";

_fileMetadata = new SFFileMetadata()
{
stageInfo = new PutGetStageInfo()
Expand Down Expand Up @@ -329,7 +333,7 @@ public void TestDownloadFile(HttpStatusCode httpStatusCode, ResultStatus expecte
_fileMetadata.stageInfo.location = httpStatusCode.ToString();

// Act
_client.DownloadFile(_fileMetadata, DownloadFileName, Parallel);
_client.DownloadFile(_fileMetadata, t_downloadFileName, Parallel);

// Assert
Assert.AreEqual(expectedResultStatus.ToString(), _fileMetadata.resultStatus);
Expand Down Expand Up @@ -376,7 +380,7 @@ public async Task TestDownloadFileAsync(HttpStatusCode httpStatusCode, ResultSta
_fileMetadata.stageInfo.location = httpStatusCode.ToString();

// Act
await _client.DownloadFileAsync(_fileMetadata, DownloadFileName, Parallel, _cancellationToken).ConfigureAwait(false);
await _client.DownloadFileAsync(_fileMetadata, t_downloadFileName, Parallel, _cancellationToken).ConfigureAwait(false);

// Assert
Assert.AreEqual(expectedResultStatus.ToString(), _fileMetadata.resultStatus);
Expand Down
Loading