Correct cancelling behavior

This commit is contained in:
benbierens 2023-06-29 10:23:04 +02:00
parent b42570be14
commit dc38797ee7
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 41 additions and 27 deletions

View File

@ -40,6 +40,8 @@ namespace CodexNetDeployer
var tokenAddress = gethResult.MarketplaceNetwork.Marketplace.TokenAddress;
var marketAccess = new MarketplaceAccess(lifecycle, gethResult.MarketplaceNetwork, account, codexAccess);
try
{
var debugInfo = codexAccess.Node.GetDebugInfo();
if (!string.IsNullOrWhiteSpace(debugInfo.spr))
{
@ -64,8 +66,15 @@ namespace CodexNetDeployer
return container;
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception:" + ex.ToString());
}
Console.Write("Unknown failure. Downloading container log." + Environment.NewLine);
lifecycle.DownloadLog(container);
Console.Write("Unknown failure." + Environment.NewLine);
return null;
}

View File

@ -44,7 +44,7 @@ namespace ContinuousTests
public IFileManager FileManager { get; private set; } = null!;
public Configuration Configuration { get; private set; } = null!;
public virtual ITimeSet TimeSet { get { return new DefaultTimeSet(); } }
public CancellationToken CancelToken { get; private set; } = null;
public CancellationToken CancelToken { get; private set; } = new CancellationToken();
public NodeRunner NodeRunner { get; private set; } = null!;
public abstract int RequiredNumberOfNodes { get; }

View File

@ -34,17 +34,18 @@ namespace ContinuousTests
foreach (var testLoop in testLoops)
{
cancelToken.ThrowIfCancellationRequested();
if (cancelToken.IsCancellationRequested) break;
overviewLog.Log("Launching test-loop for " + testLoop.Name);
testLoop.Begin();
Thread.Sleep(TimeSpan.FromSeconds(15));
}
overviewLog.Log("All test-loops launched.");
overviewLog.Log("Finished launching test-loops.");
cancelToken.WaitHandle.WaitOne();
overviewLog.Log("Cancelling all test-loops...");
taskFactory.WaitAll();
overviewLog.Log("All tasks cancelled.");
}
private void ClearAllCustomNamespaces(ContinuousTest[] allTests, FixtureLog log)

View File

@ -65,28 +65,32 @@ namespace ContinuousTests.Tests
{
var lastState = "";
var waitStart = DateTime.UtcNow;
var filesizeInMb = fileSize.SizeInBytes / 1024;
var filesizeInMb = fileSize.SizeInBytes / (1024 * 1024);
var maxWaitTime = TimeSpan.FromSeconds(filesizeInMb * 10.0);
Log.Log(nameof(WaitForContractToStart) + " for " + Time.FormatDuration(maxWaitTime));
Log.Log($"{nameof(WaitForContractToStart)} for {Time.FormatDuration(maxWaitTime)}");
while (lastState != "started")
{
CancelToken.ThrowIfCancellationRequested();
var purchaseStatus = codexAccess.Node.GetPurchaseStatus(purchaseId);
var statusJson = JsonConvert.SerializeObject(purchaseStatus);
if (purchaseStatus != null && purchaseStatus.state != lastState)
{
lastState = purchaseStatus.state;
Log.Log("Purchase status: " + statusJson);
}
Thread.Sleep(2000);
if (lastState == "errored")
{
Assert.Fail("Contract start failed: " + JsonConvert.SerializeObject(purchaseStatus));
Assert.Fail("Contract start failed: " + statusJson);
}
if (DateTime.UtcNow - waitStart > maxWaitTime)
{
Assert.Fail($"Contract was not picked up within {maxWaitTime.TotalSeconds} seconds timeout: " + JsonConvert.SerializeObject(purchaseStatus));
Assert.Fail($"Contract was not picked up within {maxWaitTime.TotalSeconds} seconds timeout: {statusJson}");
}
}
Log.Log("Contract started.");