diff --git a/Snowflake.Data.Tests/UnitTests/Tools/TimeoutHelperTest.cs b/Snowflake.Data.Tests/UnitTests/Tools/TimeoutHelperTest.cs index 743eab111..8bda40b73 100644 --- a/Snowflake.Data.Tests/UnitTests/Tools/TimeoutHelperTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Tools/TimeoutHelperTest.cs @@ -14,7 +14,7 @@ public void TestInfinity(TimeSpan infiniteTimeout) { // act var isInfinite = TimeoutHelper.IsInfinite(infiniteTimeout); - + // assert Assert.IsTrue(isInfinite); } @@ -25,7 +25,7 @@ public void TestFiniteValue(TimeSpan finiteTimeout) { // act var isInfinite = TimeoutHelper.IsInfinite(finiteTimeout); - + // assert Assert.IsFalse(isInfinite); } @@ -36,7 +36,7 @@ public void TestZeroLength(TimeSpan zeroTimeout) { // act var isZeroLength = TimeoutHelper.IsZeroLength(zeroTimeout); - + // assert Assert.IsTrue(isZeroLength); } @@ -47,11 +47,11 @@ public void TestNonZeroLength(TimeSpan nonZeroTimeout) { // act var isZeroLength = TimeoutHelper.IsZeroLength(nonZeroTimeout); - + // assert Assert.IsFalse(isZeroLength); } - + [Test] [TestCase(1000, 1000)] [TestCase(1000, 2000)] @@ -59,7 +59,7 @@ public void TestInfiniteTimeoutDoesNotExpire(long startedAtMillis, long nowMilli { // act var isExpired = TimeoutHelper.IsExpired(startedAtMillis, nowMillis, TimeoutHelper.Infinity()); - + // assert Assert.IsFalse(isExpired); } @@ -74,7 +74,7 @@ public void TestExpiredTimeout(long startedAtMillis, long nowMillis, long timeou { // arrange var timeout = TimeSpan.FromMilliseconds(timeoutMillis); - + // act var isExpired = TimeoutHelper.IsExpired(startedAtMillis, nowMillis, timeout); @@ -82,18 +82,46 @@ public void TestExpiredTimeout(long startedAtMillis, long nowMillis, long timeou Assert.AreEqual(expectedIsExpired, isExpired); } + [Test] + public void TestInfiniteTimeoutNeverExpires() + { + // act + var isExpired = TimeoutHelper.IsExpired(1000, TimeoutHelper.Infinity()); + + // assert + Assert.IsFalse(isExpired); + } + + [Test] + [TestCase(0, 0, true)] + [TestCase(1000, 0, true)] + [TestCase(100, 100, true)] + [TestCase(99, 100, false)] + [TestCase(1000, 100, true)] + public void TestExpiredTimeoutByDuration(long durationMillis, long timeoutMillis, bool expectedIsExpired) + { + // arrange + var timeout = TimeSpan.FromMilliseconds(timeoutMillis); + + // act + var isExpired = TimeoutHelper.IsExpired(durationMillis, timeout); + + // assert + Assert.AreEqual(expectedIsExpired, isExpired); + } + [Test] public void TestFiniteTimeoutLeftFailsForInfiniteTimeout() { // act var thrown = Assert.Throws(() => TimeoutHelper.FiniteTimeoutLeftMillis(1000, 2000, TimeoutHelper.Infinity())); - + // assert Assert.That(thrown.Message, Does.Contain("Infinite timeout cannot be used to determine milliseconds left")); } - + [Test] [TestCase(1000, 1000, 0, 0)] [TestCase(1000, 2000, 0, 0)] @@ -103,20 +131,20 @@ public void TestFiniteTimeoutLeft(long startedAtMillis, long nowMillis, long tim { // arrange var timeout = TimeSpan.FromMilliseconds(timeoutMillis); - + // act var millisLeft = TimeoutHelper.FiniteTimeoutLeftMillis(startedAtMillis, nowMillis, timeout); - + // assert Assert.AreEqual(expectedMillisLeft, millisLeft); - } - + } + public static IEnumerable InfiniteTimeouts() { yield return TimeoutHelper.Infinity(); yield return TimeSpan.FromMilliseconds(-1); } - + public static IEnumerable FiniteTimeouts() { yield return TimeSpan.Zero; @@ -130,7 +158,7 @@ public static IEnumerable ZeroLengthTimeouts() yield return TimeSpan.FromMilliseconds(0); yield return TimeSpan.FromSeconds(0); } - + public static IEnumerable NonZeroLengthTimeouts() { yield return TimeoutHelper.Infinity();