diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index 2b6ddcb2..5b4461e1 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -14,7 +14,7 @@ namespace CodexPlugin { string GetName(); string GetPeerId(); - DebugInfo GetDebugInfo(); + DebugInfo GetDebugInfo(bool log = false); string GetSpr(); DebugPeer GetDebugPeer(string peerId); ContentId UploadFile(TrackedFile file); @@ -123,11 +123,14 @@ namespace CodexPlugin return peerId; } - public DebugInfo GetDebugInfo() + public DebugInfo GetDebugInfo(bool log = false) { var debugInfo = CodexAccess.GetDebugInfo(); - var known = string.Join(",", debugInfo.Table.Nodes.Select(n => n.PeerId)); - Log($"Got DebugInfo with id: {debugInfo.Id}. This node knows: [{known}]"); + if (log) + { + var known = string.Join(",", debugInfo.Table.Nodes.Select(n => n.PeerId)); + Log($"Got DebugInfo with id: {debugInfo.Id}. This node knows: [{known}]"); + } return debugInfo; } diff --git a/Tests/CodexReleaseTests/NodeTests/PeerTableTests.cs b/Tests/CodexReleaseTests/NodeTests/PeerTableTests.cs index f61a4219..ced42922 100644 --- a/Tests/CodexReleaseTests/NodeTests/PeerTableTests.cs +++ b/Tests/CodexReleaseTests/NodeTests/PeerTableTests.cs @@ -1,5 +1,6 @@ using CodexPlugin; using CodexTests; +using CodexTests.Helpers; using NUnit.Framework; using System; using System.Collections.Generic; @@ -18,43 +19,13 @@ namespace CodexReleaseTests.NodeTests { var nodes = StartCodex(10); - var retry = new Retry( - description: nameof(PeerTableCompleteness), - maxTimeout: TimeSpan.FromMinutes(2), - sleepAfterFail: TimeSpan.FromSeconds(5), - onFail: f => { } - ); - - retry.Run(() => AssertAllNodesSeeEachOther(nodes)); + AssertAllNodesSeeEachOther(nodes.Concat([BootstrapNode!])); } - private void AssertAllNodesSeeEachOther(ICodexNodeGroup nodes) + private void AssertAllNodesSeeEachOther(IEnumerable nodes) { - foreach (var a in nodes) - { - AssertHasSeenAllOtherNodes(a, nodes); - } - } - - private void AssertHasSeenAllOtherNodes(ICodexNode node, ICodexNodeGroup nodes) - { - var localNode = node.GetDebugInfo().Table.LocalNode; - - foreach (var other in nodes) - { - var info = other.GetDebugInfo(); - if (info.Table.LocalNode.PeerId != localNode.PeerId) - { - AssertContainsPeerId(info, localNode.PeerId); - } - } - } - - private void AssertContainsPeerId(DebugInfo info, string peerId) - { - var entry = info.Table.Nodes.SingleOrDefault(n => n.PeerId == peerId); - if (entry == null) throw new Exception("Table entry not found."); - if (!entry.Seen) throw new Exception("Peer not seen."); + var helper = new PeerConnectionTestHelpers(GetTestLog()); + helper.AssertFullyConnected(nodes); } } }