logs all checks before failing

This commit is contained in:
benbierens 2023-05-10 10:47:10 +02:00
parent d58cb38c79
commit e9679e18c0
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 29 additions and 11 deletions

View File

@ -17,41 +17,59 @@ namespace Tests.PeerDiscoveryTests
{ {
Time.Retry(() => Time.Retry(() =>
{ {
for (var x = 0; x < nodes.Length; x++) var infos = nodes.Select(n => FetchDebugInfo(n, log)).ToArray();
var failureMessags = new List<string>();
for (var x = 0; x < infos.Length; x++)
{ {
for (var y = x + 1; y < nodes.Length; y++) for (var y = x + 1; y < infos.Length; y++)
{ {
AssertKnowEachother(nodes[x], nodes[y], log); AssertKnowEachother(failureMessags, infos[x], infos[y], log);
} }
} }
CollectionAssert.IsEmpty(failureMessags);
}); });
} }
private static void AssertKnowEachother(IOnlineCodexNode a, IOnlineCodexNode b, BaseLog? log) private static CodexDebugResponse FetchDebugInfo(IOnlineCodexNode n, BaseLog? log)
{ {
AssertKnowEachother(a.GetDebugInfo(), b.GetDebugInfo(), log); var info = n.GetDebugInfo();
if (log != null)
{
log.AddStringReplace(info.table.localNode.nodeId, $"-<{n.GetName()}>-");
} }
private static void AssertKnowEachother(CodexDebugResponse a, CodexDebugResponse b, BaseLog? log) return info;
{
AssertKnows(a, b, log);
AssertKnows(b, a, log);
} }
private static void AssertKnows(CodexDebugResponse a, CodexDebugResponse b, BaseLog? log) private static void AssertKnowEachother(List<string> failureMessags, CodexDebugResponse a, CodexDebugResponse b, BaseLog? log)
{
AssertKnows(failureMessags, a, b, log);
AssertKnows(failureMessags, b, a, log);
}
private static void AssertKnows(List<string> failureMessags, CodexDebugResponse a, CodexDebugResponse b, BaseLog? log)
{ {
//var enginePeers = string.Join(",", a.enginePeers.Select(p => p.peerId)); //var enginePeers = string.Join(",", a.enginePeers.Select(p => p.peerId));
//var switchPeers = string.Join(",", a.switchPeers.Select(p => p.peerId)); //var switchPeers = string.Join(",", a.switchPeers.Select(p => p.peerId));
var tableNodes = string.Join(",", a.table.nodes.Select(n => n.nodeId)); var tableNodes = string.Join(",", a.table.nodes.Select(n => n.nodeId));
var success = a.table.nodes.Any(n => n.nodeId == b.table.localNode.nodeId);
if (log != null) if (log != null)
{ {
log.Debug($"{a.table.localNode.nodeId} is looking for {b.table.localNode.nodeId} in table-nodes [{tableNodes}]"); var msg = success ? "PASS" : "FAIL";
log.Log($"{msg} {a.table.localNode.nodeId} is looking for {b.table.localNode.nodeId} in table-nodes [{tableNodes}]");
} }
//Assert.That(a.enginePeers.Any(p => p.peerId == b.id), $"{a.id} was looking for '{b.id}' in engine-peers [{enginePeers}] but it was not found."); //Assert.That(a.enginePeers.Any(p => p.peerId == b.id), $"{a.id} was looking for '{b.id}' in engine-peers [{enginePeers}] but it was not found.");
//Assert.That(a.switchPeers.Any(p => p.peerId == b.id), $"{a.id} was looking for '{b.id}' in switch-peers [{switchPeers}] but it was not found."); //Assert.That(a.switchPeers.Any(p => p.peerId == b.id), $"{a.id} was looking for '{b.id}' in switch-peers [{switchPeers}] but it was not found.");
Assert.That(a.table.nodes.Any(n => n.nodeId == b.table.localNode.nodeId), $"{a.table.localNode.nodeId} was looking for '{b.table.localNode.nodeId}' in table-nodes [{tableNodes}] but it was not found."); if (!success)
{
failureMessags.Add($"{a.table.localNode.nodeId} was looking for '{b.table.localNode.nodeId}' in table-nodes [{tableNodes}] but it was not found.");
}
} }
} }
} }