From 74a0f0c075716c9c97f2482be270e85da994d1c2 Mon Sep 17 00:00:00 2001 From: Krzysztof Nozderko Date: Tue, 2 Jan 2024 17:10:11 +0100 Subject: [PATCH] time based stopwatch --- .../ConnectionMultiplePoolsIT.cs | 8 +++--- Snowflake.Data.Tests/Util/StopWatch.cs | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 Snowflake.Data.Tests/Util/StopWatch.cs diff --git a/Snowflake.Data.Tests/IntegrationTests/ConnectionMultiplePoolsIT.cs b/Snowflake.Data.Tests/IntegrationTests/ConnectionMultiplePoolsIT.cs index 069db4d97..f25ed353b 100644 --- a/Snowflake.Data.Tests/IntegrationTests/ConnectionMultiplePoolsIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/ConnectionMultiplePoolsIT.cs @@ -1,8 +1,6 @@ using System; using System.Data; -using System.Diagnostics; using System.Linq; -using System.Threading; using System.Threading.Tasks; using NUnit.Framework; using Snowflake.Data.Client; @@ -113,7 +111,7 @@ public void TestWaitForTheIdleConnectionWhenExceedingMaxConnectionsLimit() pool.SetWaitingTimeout(1000); var conn1 = OpenedConnection(connectionString); var conn2 = OpenedConnection(connectionString); - var watch = new Stopwatch(); + var watch = new StopWatch(); // act watch.Start(); @@ -145,7 +143,7 @@ public void TestWaitForTheIdleConnectionWhenExceedingMaxConnectionsLimitAsync() pool.SetWaitingTimeout(1000); var conn1 = OpenedConnection(connectionString); var conn2 = OpenedConnection(connectionString); - var watch = new Stopwatch(); + var watch = new StopWatch(); // act watch.Start(); @@ -180,7 +178,7 @@ public void TestWaitInAQueueForAnIdleSession() .NewThread("B", 50, 2000, true) .NewThread("C", 100, 0, true) .NewThread("D", 150, 0, true); - var watch = new Stopwatch(); + var watch = new StopWatch(); // act watch.Start(); diff --git a/Snowflake.Data.Tests/Util/StopWatch.cs b/Snowflake.Data.Tests/Util/StopWatch.cs new file mode 100644 index 000000000..0ef200508 --- /dev/null +++ b/Snowflake.Data.Tests/Util/StopWatch.cs @@ -0,0 +1,25 @@ +using System; + +namespace Snowflake.Data.Tests.Util +{ + internal class StopWatch + { + private long _startMillis; + private long _stopMillis; + + public long ElapsedMilliseconds + { + get => _stopMillis - _startMillis; + } + + public void Start() + { + _startMillis = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + } + + public void Stop() + { + _stopMillis = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + } + } +}