Better logging for Time.WaitUntil.
This commit is contained in:
parent
d847c4f3ec
commit
015d8da21d
|
@ -904,7 +904,7 @@ namespace KubernetesWorkflow
|
||||||
var sw = Stopwatch.Begin(log, true);
|
var sw = Stopwatch.Begin(log, true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Time.WaitUntil(predicate, cluster.K8sOperationTimeout(), cluster.K8sOperationRetryDelay());
|
Time.WaitUntil(predicate, cluster.K8sOperationTimeout(), cluster.K8sOperationRetryDelay(), msg);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,24 +57,27 @@
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WaitUntil(Func<bool> predicate)
|
public static void WaitUntil(Func<bool> predicate, string msg)
|
||||||
{
|
{
|
||||||
WaitUntil(predicate, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1));
|
WaitUntil(predicate, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WaitUntil(Func<bool> predicate, TimeSpan timeout, TimeSpan retryDelay)
|
public static void WaitUntil(Func<bool> predicate, TimeSpan timeout, TimeSpan retryDelay, string msg)
|
||||||
{
|
{
|
||||||
var start = DateTime.UtcNow;
|
var start = DateTime.UtcNow;
|
||||||
|
var tries = 1;
|
||||||
var state = predicate();
|
var state = predicate();
|
||||||
while (!state)
|
while (!state)
|
||||||
{
|
{
|
||||||
if (DateTime.UtcNow - start > timeout)
|
var duration = DateTime.UtcNow - start;
|
||||||
|
if (duration > timeout)
|
||||||
{
|
{
|
||||||
throw new TimeoutException("Operation timed out.");
|
throw new TimeoutException($"Operation timed out after {tries} tries over (total) {FormatDuration(duration)}. '{msg}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
Sleep(retryDelay);
|
Sleep(retryDelay);
|
||||||
state = predicate();
|
state = predicate();
|
||||||
|
tries++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace CodexContractsPlugin
|
||||||
var logHandler = new ContractsReadyLogHandler(tools.GetLog());
|
var logHandler = new ContractsReadyLogHandler(tools.GetLog());
|
||||||
workflow.DownloadContainerLog(container, logHandler, 100);
|
workflow.DownloadContainerLog(container, logHandler, 100);
|
||||||
return logHandler.Found;
|
return logHandler.Found;
|
||||||
});
|
}, nameof(DeployContract));
|
||||||
Log("Contracts deployed. Extracting addresses...");
|
Log("Contracts deployed. Extracting addresses...");
|
||||||
|
|
||||||
var extractor = new ContractsContainerInfoExtractor(tools.GetLog(), workflow, container);
|
var extractor = new ContractsContainerInfoExtractor(tools.GetLog(), workflow, container);
|
||||||
|
@ -71,7 +71,7 @@ namespace CodexContractsPlugin
|
||||||
|
|
||||||
Log("Extract completed. Checking sync...");
|
Log("Extract completed. Checking sync...");
|
||||||
|
|
||||||
Time.WaitUntil(() => interaction.IsSynced(marketplaceAddress, abi));
|
Time.WaitUntil(() => interaction.IsSynced(marketplaceAddress, abi), nameof(DeployContract));
|
||||||
|
|
||||||
Log("Synced. Codex SmartContracts deployed.");
|
Log("Synced. Codex SmartContracts deployed.");
|
||||||
|
|
||||||
|
@ -83,9 +83,9 @@ namespace CodexContractsPlugin
|
||||||
tools.GetLog().Log(msg);
|
tools.GetLog().Log(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WaitUntil(Func<bool> predicate)
|
private void WaitUntil(Func<bool> predicate, string msg)
|
||||||
{
|
{
|
||||||
Time.WaitUntil(predicate, TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(2));
|
Time.WaitUntil(predicate, TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(2), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StartupConfig CreateStartupConfig(IGethNode gethNode)
|
private StartupConfig CreateStartupConfig(IGethNode gethNode)
|
||||||
|
|
|
@ -154,7 +154,7 @@ namespace CodexTests.BasicTests
|
||||||
var newBytes = Convert.ToInt64(afterBytesStored.Values.Last().Value - beforeBytesStored.Values.Last().Value);
|
var newBytes = Convert.ToInt64(afterBytesStored.Values.Last().Value - beforeBytesStored.Values.Last().Value);
|
||||||
|
|
||||||
return high > newBytes && newBytes > low;
|
return high > newBytes && newBytes > low;
|
||||||
}, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(2));
|
}, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(2), nameof(ContinuousSubstitute));
|
||||||
|
|
||||||
FileUtils.TrackedFile? downloadedFile = null;
|
FileUtils.TrackedFile? downloadedFile = null;
|
||||||
LogBytesPerMillisecond(() => downloadedFile = secondary.DownloadContent(contentId));
|
LogBytesPerMillisecond(() => downloadedFile = secondary.DownloadContent(contentId));
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace CodexTests.BasicTests
|
||||||
{
|
{
|
||||||
node = Ci.StartCodexNode();
|
node = Ci.StartCodexNode();
|
||||||
|
|
||||||
Time.WaitUntil(() => node == null, TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5));
|
Time.WaitUntil(() => node == null, TimeSpan.FromMinutes(5), TimeSpan.FromSeconds(5), nameof(SetUpANodeAndWait));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -27,7 +27,7 @@ namespace CodexTests.BasicTests
|
||||||
{
|
{
|
||||||
var myNode = Ci.StartCodexNode();
|
var myNode = Ci.StartCodexNode();
|
||||||
|
|
||||||
Time.WaitUntil(() => node != null, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(5));
|
Time.WaitUntil(() => node != null, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(5), nameof(ForeignNodeConnects));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace DistTestCore.Helpers
|
||||||
Time.WaitUntil(() => {
|
Time.WaitUntil(() => {
|
||||||
var c = constraint.Resolve();
|
var c = constraint.Resolve();
|
||||||
return c.ApplyTo(actual()).IsSuccess;
|
return c.ApplyTo(actual()).IsSuccess;
|
||||||
});
|
}, "RetryAssert: " + message);
|
||||||
}
|
}
|
||||||
catch (TimeoutException)
|
catch (TimeoutException)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue