Skip to content

Commit

Permalink
fix retries on tests performance results
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko committed Apr 22, 2024
1 parent c4dfd2e commit 79dd04a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Snowflake.Data.Tests/SFBaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace Snowflake.Data.Tests
using Newtonsoft.Json.Serialization;

/*
* This is the base class for all tests that call blocking methods in the library - it uses MockSynchronizationContext to verify that
* This is the base class for all tests that call blocking methods in the library - it uses MockSynchronizationContext to verify that
* there are no async deadlocks in the library
*
*
*/
[TestFixture]
public class SFBaseTest : SFBaseTestAsync
Expand All @@ -47,7 +47,7 @@ public static void TearDownContext()

/*
* This is the base class for all tests that call async methods in the library - it does not use a special SynchronizationContext
*
*
*/
[TestFixture]
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
Expand All @@ -65,12 +65,12 @@ public class SFBaseTestAsync
protected virtual string TestName => TestContext.CurrentContext.Test.MethodName;
protected string TestNameWithWorker => TestName + TestContext.CurrentContext.WorkerId?.Replace("#", "_");
protected string TableName => TestNameWithWorker;


private Stopwatch _stopwatch;

private List<string> _tablesToRemove;

[SetUp]
public void BeforeTest()
{
Expand All @@ -93,7 +93,7 @@ private void RemoveTables()
{
if (_tablesToRemove.Count == 0)
return;

using (var conn = new SnowflakeDbConnection(ConnectionString))
{
conn.Open();
Expand Down Expand Up @@ -148,26 +148,26 @@ public SFBaseTestAsync()
string.Format(ConnectionStringSnowflakeAuthFmt,
testConfig.user,
testConfig.password);

protected string ConnectionStringWithInvalidUserName => ConnectionStringWithoutAuth +
string.Format(ConnectionStringSnowflakeAuthFmt,
"unknown",
testConfig.password);

protected TestConfig testConfig { get; }

protected string ResolveHost()
{
return testConfig.host ?? $"{testConfig.account}.snowflakecomputing.com";
}
}

[SetUpFixture]
public class TestEnvironment
{
private const string ConnectionStringFmt = "scheme={0};host={1};port={2};" +
private const string ConnectionStringFmt = "scheme={0};host={1};port={2};" +
"account={3};role={4};db={5};warehouse={6};user={7};password={8};";

public static TestConfig TestConfig { get; private set; }

private static Dictionary<string, TimeSpan> s_testPerformance;
Expand All @@ -178,7 +178,7 @@ public static void RecordTestPerformance(string name, TimeSpan time)
{
lock (s_testPerformanceLock)
{
s_testPerformance.Add(name, time);
s_testPerformance[name] = time;
}
}

Expand All @@ -201,7 +201,7 @@ public void Setup()

var testConfigString = reader.ReadToEnd();

// Local JSON settings to avoid using system wide settings which could be different
// Local JSON settings to avoid using system wide settings which could be different
// than the default ones
var jsonSettings = new JsonSerializerSettings
{
Expand All @@ -221,16 +221,16 @@ public void Setup()
{
Assert.Fail("Failed to load test configuration");
}

ModifySchema(TestConfig.schema, SchemaAction.CREATE);
}

[OneTimeTearDown]
public void Cleanup()
{
ModifySchema(TestConfig.schema, SchemaAction.DROP);
}

[OneTimeSetUp]
public void SetupTestPerformance()
{
Expand All @@ -243,12 +243,12 @@ public void CreateTestTimeArtifact()
var resultText = "test;time_in_ms\n";
resultText += string.Join("\n",
s_testPerformance.Select(test => $"{test.Key};{Math.Round(test.Value.TotalMilliseconds,0)}"));

var dotnetVersion = Environment.GetEnvironmentVariable("net_version");
var cloudEnv = Environment.GetEnvironmentVariable("snowflake_cloud_env");

var separator = Path.DirectorySeparatorChar;

// We have to go up 3 times as the working directory path looks as follows:
// Snowflake.Data.Tests/bin/debug/{.net_version}/
File.WriteAllText($"..{separator}..{separator}..{separator}{GetOs()}_{dotnetVersion}_{cloudEnv}_performance.csv", resultText);
Expand Down

0 comments on commit 79dd04a

Please sign in to comment.