Skip to content

Commit

Permalink
SNOW-893834 other tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dstempniak committed Oct 20, 2023
1 parent fd17f45 commit 1752c5c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
53 changes: 25 additions & 28 deletions Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,40 +1711,37 @@ public void TestCancelLoginBeforeTimeout()
[Test]
public void TestAsyncLoginTimeout()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
using (var conn = new MockSnowflakeDbConnection())
{
using (var conn = new MockSnowflakeDbConnection())
{
int timeoutSec = 5;
string loginTimeOut5sec = String.Format(ConnectionString + "connection_timeout={0}",
timeoutSec);
conn.ConnectionString = loginTimeOut5sec;
int timeoutSec = 5;
string loginTimeOut5sec = String.Format(ConnectionString + "connection_timeout={0}",
timeoutSec);
conn.ConnectionString = loginTimeOut5sec;

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

Stopwatch stopwatch = Stopwatch.StartNew();
try
{
Task connectTask = conn.OpenAsync(CancellationToken.None);
connectTask.Wait();
}
catch (AggregateException e)
{
Assert.AreEqual(SFError.INTERNAL_ERROR.GetAttribute<SFErrorAttr>().errorCode,
((SnowflakeDbException)e.InnerException).ErrorCode);
Stopwatch stopwatch = Stopwatch.StartNew();
try
{
Task connectTask = conn.OpenAsync(CancellationToken.None);
connectTask.Wait();
}
catch (AggregateException e)
{
Assert.AreEqual(SFError.INTERNAL_ERROR.GetAttribute<SFErrorAttr>().errorCode,
((SnowflakeDbException)e.InnerException).ErrorCode);

}
stopwatch.Stop();
int detla = 10; //in case server time slower.
}
stopwatch.Stop();
int detla = 10; //in case server time slower.

// Should timeout after 5sec
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 5 * 1000 - detla);
// But never more than 1 sec (max backoff) after the default timeout
Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, (6) * 1000);
// Should timeout after 5sec
Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 5 * 1000 - detla);
// But never more than 2 sec (max backoff) after the default timeout
Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, 7 * 1000);

Assert.AreEqual(ConnectionState.Closed, conn.State);
Assert.AreEqual(5, conn.ConnectionTimeout);
}
Assert.AreEqual(ConnectionState.Closed, conn.State);
Assert.AreEqual(5, conn.ConnectionTimeout);
}
}

Expand Down
16 changes: 7 additions & 9 deletions Snowflake.Data.Tests/UnitTests/Logger/EasyLoggerManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class EasyLoggerManagerTest
private const string ErrorMessage = "Easy logging Error message";
private const string FatalMessage = "Easy logging Fatal message";
private static readonly string s_logsDirectory = Path.GetTempPath();

[ThreadStatic]
private static string t_directoryLogPath;
private string _directoryLogPath;

[OneTimeTearDown]
public static void CleanUp()
Expand All @@ -35,21 +33,21 @@ public static void CleanUp()
[SetUp]
public void BeforeEach()
{
t_directoryLogPath = RandomLogsDirectoryPath();
_directoryLogPath = RandomLogsDirectoryPath();
}

[TearDown]
public void AfterEach()
{
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Warn, t_directoryLogPath);
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Warn, _directoryLogPath);
}

[Test]
public void TestThatChangesLogLevel()
{
// arrange
var logger = SFLoggerFactory.GetLogger<SFBlockingChunkDownloaderV3>();
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Warn, t_directoryLogPath);
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Warn, _directoryLogPath);

// assert
Assert.IsFalse(logger.IsDebugEnabled());
Expand All @@ -59,7 +57,7 @@ public void TestThatChangesLogLevel()
Assert.IsTrue(logger.IsFatalEnabled());

// act
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Debug, t_directoryLogPath);
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Debug, _directoryLogPath);

// assert
Assert.IsTrue(logger.IsDebugEnabled());
Expand All @@ -74,7 +72,7 @@ public void TestThatLogsToProperFileWithProperLogLevelOnly()
{
// arrange
var logger = SFLoggerFactory.GetLogger<SFBlockingChunkDownloaderV3>();
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Info, t_directoryLogPath);
EasyLoggerManager.Instance.ReconfigureEasyLogging(EasyLoggingLogLevel.Info, _directoryLogPath);

// act
logger.Debug(DebugMessage);
Expand All @@ -84,7 +82,7 @@ public void TestThatLogsToProperFileWithProperLogLevelOnly()
logger.Fatal(FatalMessage);

// assert
var logLines = File.ReadLines(FindLogFilePath(t_directoryLogPath));
var logLines = File.ReadLines(FindLogFilePath(_directoryLogPath));
Assert.That(logLines, Has.Exactly(0).Matches<string>(s => s.Contains(DebugMessage)));
Assert.That(logLines, Has.Exactly(1).Matches<string>(s => s.Contains(InfoMessage)));
Assert.That(logLines, Has.Exactly(1).Matches<string>(s => s.Contains(WarnMessage)));
Expand Down

0 comments on commit 1752c5c

Please sign in to comment.