diff --git a/Framework/Utils/Time.cs b/Framework/Utils/Time.cs index 3a53b72..d6df480 100644 --- a/Framework/Utils/Time.cs +++ b/Framework/Utils/Time.cs @@ -56,12 +56,12 @@ public static void Retry(Action action, int maxRetries, string description) { - Retry(action, maxRetries, TimeSpan.FromSeconds(1), description); + Retry(action, maxRetries, TimeSpan.FromSeconds(5), description); } public static T Retry(Func action, int maxRetries, string description) { - return Retry(action, maxRetries, TimeSpan.FromSeconds(1), description); + return Retry(action, maxRetries, TimeSpan.FromSeconds(5), description); } public static void Retry(Action action, int maxRetries, TimeSpan retryTime, string description) diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index 0a3c659..d0a0636 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -165,8 +165,9 @@ namespace CodexPlugin throw new Exception($"Invalid version information received from Codex node {GetName()}: {debugInfo.codex}"); } - //lifecycle.Log.AddStringReplace(nodePeerId, nodeName); - //lifecycle.Log.AddStringReplace(debugInfo.table.localNode.nodeId, nodeName); + var log = tools.GetLog(); + log.AddStringReplace(nodePeerId, nodeName); + log.AddStringReplace(debugInfo.table.localNode.nodeId, nodeName); Version = debugInfo.codex; } diff --git a/Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs b/Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs index 8f753ae..6c8e66c 100644 --- a/Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs +++ b/Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs @@ -1,5 +1,6 @@ using CodexPlugin; using NUnit.Framework; +using Utils; namespace CodexTests.PeerDiscoveryTests { @@ -18,23 +19,33 @@ namespace CodexTests.PeerDiscoveryTests } private void AssertRoutingTable() + { + Time.Retry(CheckRoutingTable, 3, nameof(CheckRoutingTable)); + } + + private void CheckRoutingTable() { var all = GetAllOnlineCodexNodes(); - var allNodeIds = all.Select(n => n.GetDebugInfo().table.localNode.nodeId).ToArray(); - - var errors = all.Select(n => AreAllPresent(n, allNodeIds)).Where(s => !string.IsNullOrEmpty(s)).ToArray(); + var allResponses = all.Select(n => n.GetDebugInfo()).ToArray(); + var errors = new List(); + foreach (var response in allResponses) + { + var error = AreAllPresent(response, allResponses); + if (!string.IsNullOrEmpty(error)) errors.Add(error); + } + if (errors.Any()) { Assert.Fail(string.Join(Environment.NewLine, errors)); } } - private string AreAllPresent(ICodexNode n, string[] allNodesIds) + private string AreAllPresent(CodexDebugResponse info, CodexDebugResponse[] allResponses) { - var info = n.GetDebugInfo(); var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray(); - var expectedIds = allNodesIds.Where(id => id != info.table.localNode.nodeId).ToArray(); + var allOthers = GetAllOtherResponses(info, allResponses); + var expectedIds = allOthers.Select(i => i.table.localNode.nodeId).ToArray(); if (!expectedIds.All(ex => knownIds.Contains(ex))) { @@ -43,5 +54,10 @@ namespace CodexTests.PeerDiscoveryTests return string.Empty; } + + private CodexDebugResponse[] GetAllOtherResponses(CodexDebugResponse exclude, CodexDebugResponse[] allResponses) + { + return allResponses.Where(r => r.id != exclude.id).ToArray(); + } } }