diff --git a/Tests/PeerDiscoveryTests/PeerTestHelpers.cs b/Tests/PeerDiscoveryTests/PeerTestHelpers.cs index 6b33ddd..af2a3ac 100644 --- a/Tests/PeerDiscoveryTests/PeerTestHelpers.cs +++ b/Tests/PeerDiscoveryTests/PeerTestHelpers.cs @@ -17,41 +17,59 @@ namespace Tests.PeerDiscoveryTests { Time.Retry(() => { - for (var x = 0; x < nodes.Length; x++) + var infos = nodes.Select(n => FetchDebugInfo(n, log)).ToArray(); + + var failureMessags = new List(); + 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()}>-"); + } + + return info; } - private static void AssertKnowEachother(CodexDebugResponse a, CodexDebugResponse b, BaseLog? log) + private static void AssertKnowEachother(List failureMessags, CodexDebugResponse a, CodexDebugResponse b, BaseLog? log) { - AssertKnows(a, b, log); - AssertKnows(b, a, log); + AssertKnows(failureMessags, a, b, log); + AssertKnows(failureMessags, b, a, log); } - private static void AssertKnows(CodexDebugResponse a, CodexDebugResponse b, BaseLog? log) + private static void AssertKnows(List failureMessags, CodexDebugResponse a, CodexDebugResponse b, BaseLog? log) { //var enginePeers = string.Join(",", a.enginePeers.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 success = a.table.nodes.Any(n => n.nodeId == b.table.localNode.nodeId); + 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.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."); + } } } }