Skip to content

Commit

Permalink
chore: Add generic WaitForResultEqual in RuntimeTests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjohnoliver committed Aug 9, 2021
1 parent e0b62e5 commit d682d03
Showing 1 changed file with 27 additions and 0 deletions.
Expand Up @@ -153,6 +153,33 @@ internal static async Task WaitForEqual(double expected, Func<double> actualFunc
bool ApproxEquals(double actualValue) => Math.Abs(expected - actualValue) < tolerance;
}

internal static async Task WaitForResultEqual<T>(T expected, Func<T> actualFunc, int timeoutMS = 1000)
{
if (actualFunc is null)
{
throw new ArgumentNullException(nameof(actualFunc));
}

var actual = actualFunc();
if (Equals(expected, actual))
{
return;
}

var stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < timeoutMS)
{
await WaitForIdle();
actual = actualFunc();
if (Equals(expected, actual))
{
return;
}
}

throw new AssertFailedException($"Timed out waiting for equality condition to be met. Expected {expected} but last received value was {actual}.");
}

/// <summary>
/// Wait until a specified <paramref name="condition"/> is met.
/// </summary>
Expand Down

0 comments on commit d682d03

Please sign in to comment.