fixes crash in chain monitor

This commit is contained in:
ThatBen 2025-04-27 12:10:45 +02:00
parent 5d61097838
commit ff78d7e28e
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB
3 changed files with 22 additions and 12 deletions

View File

@ -26,10 +26,10 @@ namespace CodexReleaseTests.MarketTests
this.updateInterval = updateInterval;
}
public void Start()
public void Start(Action onFailure)
{
cts = new CancellationTokenSource();
worker = Task.Run(Worker);
worker = Task.Run(() => Worker(onFailure));
}
public void Stop()
@ -39,14 +39,23 @@ namespace CodexReleaseTests.MarketTests
if (worker.Exception != null) throw worker.Exception;
}
private void Worker()
private void Worker(Action onFailure)
{
var state = new ChainState(log, contracts, new DoNothingChainEventHandler(), startUtc, doProofPeriodMonitoring: true);
Thread.Sleep(updateInterval);
while (!cts.IsCancellationRequested)
{
UpdateChainState(state);
try
{
UpdateChainState(state);
}
catch (Exception ex)
{
log.Error("Exception in chain monitor: " + ex);
onFailure();
throw;
}
cts.Token.WaitHandle.WaitOne(updateInterval);
}
@ -61,7 +70,7 @@ namespace CodexReleaseTests.MarketTests
var slots = reports.Reports.Sum(r => Convert.ToInt32(r.TotalNumSlots));
var required = reports.Reports.Sum(r => Convert.ToInt32(r.TotalProofsRequired));
var missed = reports.Reports.Sum(r => Convert.ToInt32(r.MissedProofs));
var missed = reports.Reports.Sum(r => r.MissedProofs.Length);
log.Log($"Proof report: Slots={slots} Required={required} Missed={missed}");
}

View File

@ -7,6 +7,7 @@ using DistTestCore;
using GethPlugin;
using Logging;
using Nethereum.Hex.HexConvertors.Extensions;
using NUnit.Framework;
using Utils;
namespace CodexReleaseTests.MarketTests
@ -123,7 +124,10 @@ namespace CodexReleaseTests.MarketTests
if (!MonitorChainState) return null;
var result = new ChainMonitor(log, contracts, startUtc);
result.Start();
result.Start(() =>
{
Assert.Fail("Failure in chain monitor.");
});
return result;
}

View File

@ -43,20 +43,19 @@ namespace CodexReleaseTests.MarketTests
[Values(5, 10)] int numGenerations)
{
var hosts = StartHosts();
var clients = StartClients();
for (var i = 0; i < numGenerations; i++)
{
Log("Generation: " + i);
Generation(hosts);
Generation(clients, hosts);
}
Thread.Sleep(TimeSpan.FromSeconds(12.0));
}
private void Generation(ICodexNodeGroup hosts)
private void Generation(ICodexNodeGroup clients, ICodexNodeGroup hosts)
{
var clients = StartClients();
var requests = clients.Select(CreateStorageRequest).ToArray();
All(requests, r =>
@ -67,8 +66,6 @@ namespace CodexReleaseTests.MarketTests
All(requests, r => r.WaitForStorageContractStarted());
clients.Stop(waitTillStopped: false);
// for the time being, we're only interested in whether these contracts start.
//All(requests, r => AssertContractSlotsAreFilledByHosts(r, hosts));
//All(requests, r => r.WaitForStorageContractFinished());