Adds AssertHelper for better less log-spamming retry-assert.
This commit is contained in:
parent
9328f04f4a
commit
09e550df79
|
@ -0,0 +1,22 @@
|
||||||
|
using NUnit.Framework.Constraints;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Utils;
|
||||||
|
|
||||||
|
namespace DistTestCore.Helpers
|
||||||
|
{
|
||||||
|
public static class AssertHelpers
|
||||||
|
{
|
||||||
|
public static void RetryAssert<T>(IResolveConstraint constraint, Func<T> actual, string message)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var c = constraint.Resolve();
|
||||||
|
Time.WaitUntil(() => c.ApplyTo(actual()).IsSuccess);
|
||||||
|
}
|
||||||
|
catch (TimeoutException)
|
||||||
|
{
|
||||||
|
Assert.That(actual(), constraint, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using DistTestCore.Codex;
|
using DistTestCore.Codex;
|
||||||
|
using DistTestCore.Helpers;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NUnit.Framework.Constraints;
|
using NUnit.Framework.Constraints;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
@ -97,10 +98,7 @@ namespace DistTestCore.Marketplace
|
||||||
|
|
||||||
public void AssertThatBalance(IResolveConstraint constraint, string message = "")
|
public void AssertThatBalance(IResolveConstraint constraint, string message = "")
|
||||||
{
|
{
|
||||||
Time.Retry(() =>
|
AssertHelpers.RetryAssert(constraint, GetBalance, message);
|
||||||
{
|
|
||||||
Assert.That(GetBalance(), constraint, message);
|
|
||||||
}, nameof(AssertThatBalance));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestToken GetBalance()
|
public TestToken GetBalance()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using KubernetesWorkflow;
|
using DistTestCore.Helpers;
|
||||||
|
using KubernetesWorkflow;
|
||||||
using Logging;
|
using Logging;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NUnit.Framework.Constraints;
|
using NUnit.Framework.Constraints;
|
||||||
|
@ -28,15 +29,14 @@ namespace DistTestCore.Metrics
|
||||||
|
|
||||||
public void AssertThat(string metricName, IResolveConstraint constraint, string message = "")
|
public void AssertThat(string metricName, IResolveConstraint constraint, string message = "")
|
||||||
{
|
{
|
||||||
Time.Retry(() =>
|
AssertHelpers.RetryAssert(constraint, () =>
|
||||||
{
|
{
|
||||||
var metricSet = GetMetricWithTimeout(metricName);
|
var metricSet = GetMetricWithTimeout(metricName);
|
||||||
var metricValue = metricSet.Values[0].Value;
|
var metricValue = metricSet.Values[0].Value;
|
||||||
|
|
||||||
log.Log($"{node.Name} metric '{metricName}' = {metricValue}");
|
log.Log($"{node.Name} metric '{metricName}' = {metricValue}");
|
||||||
|
return metricValue;
|
||||||
Assert.That(metricValue, constraint, message);
|
}, message);
|
||||||
}, nameof(AssertThat));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Metrics? GetAllMetrics()
|
public Metrics? GetAllMetrics()
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
result += $"{d.Seconds} secs";
|
result += $"{d.Seconds} secs";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void WaitUntil(Func<bool> predicate)
|
||||||
|
{
|
||||||
|
WaitUntil(predicate, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1));
|
||||||
|
}
|
||||||
|
|
||||||
public static void WaitUntil(Func<bool> predicate, TimeSpan timeout, TimeSpan retryTime)
|
public static void WaitUntil(Func<bool> predicate, TimeSpan timeout, TimeSpan retryTime)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue