From b7da6df7a6a9cca1144944aa87806f06ca2cd975 Mon Sep 17 00:00:00 2001 From: Savpek Date: Mon, 20 Aug 2018 18:04:07 +0300 Subject: [PATCH] Updated timeout algorithm to version where time isn't used from statics. --- .../Extensions/CallResponseExtensions.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Protacon.NetCore.WebApi.TestUtil/Extensions/CallResponseExtensions.cs b/Protacon.NetCore.WebApi.TestUtil/Extensions/CallResponseExtensions.cs index 22599fa..be89a64 100644 --- a/Protacon.NetCore.WebApi.TestUtil/Extensions/CallResponseExtensions.cs +++ b/Protacon.NetCore.WebApi.TestUtil/Extensions/CallResponseExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Net; using System.Threading; +using System.Threading.Tasks; namespace Protacon.NetCore.WebApi.TestUtil.Extensions { @@ -8,9 +9,10 @@ public static class CallResponseExtensions { public static Call WaitForStatusCode(this Call call, HttpStatusCode statusCode, TimeSpan timeout) { - DateTime endAt = DateTime.UtcNow.Add(timeout); + const int testPeriodMs = 500; + var timeUsedMs = 0; - while (true) + while(true) { try { @@ -18,12 +20,13 @@ public static Call WaitForStatusCode(this Call call, HttpStatusCode statusCode, } catch (ExpectedStatusCodeException ex) { - if (DateTime.UtcNow > endAt) + if (timeUsedMs > timeout.TotalMilliseconds) { throw ex; } - Thread.Sleep(500); + timeUsedMs += testPeriodMs; + Task.Delay(testPeriodMs).Wait(); } } }