Skip to content

Commit

Permalink
Updated timeout algorithm to version where time isn't used from statics.
Browse files Browse the repository at this point in the history
  • Loading branch information
savpek committed Aug 20, 2018
1 parent d21f50c commit b7da6df
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

namespace Protacon.NetCore.WebApi.TestUtil.Extensions
{
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
{
return call.Clone().ExpectStatusCode(statusCode);
}
catch (ExpectedStatusCodeException ex)
{
if (DateTime.UtcNow > endAt)
if (timeUsedMs > timeout.TotalMilliseconds)
{
throw ex;
}

Thread.Sleep(500);
timeUsedMs += testPeriodMs;
Task.Delay(testPeriodMs).Wait();
}
}
}
Expand Down

0 comments on commit b7da6df

Please sign in to comment.