Cleanup routing table tests. Adds retry.

This commit is contained in:
benbierens 2023-11-12 11:24:58 +01:00
parent 96ff3c38bb
commit 71ad471958
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 27 additions and 10 deletions

View File

@ -56,12 +56,12 @@
public static void Retry(Action action, int maxRetries, string description) 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<T>(Func<T> action, int maxRetries, string description) public static T Retry<T>(Func<T> 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) public static void Retry(Action action, int maxRetries, TimeSpan retryTime, string description)

View File

@ -165,8 +165,9 @@ namespace CodexPlugin
throw new Exception($"Invalid version information received from Codex node {GetName()}: {debugInfo.codex}"); throw new Exception($"Invalid version information received from Codex node {GetName()}: {debugInfo.codex}");
} }
//lifecycle.Log.AddStringReplace(nodePeerId, nodeName); var log = tools.GetLog();
//lifecycle.Log.AddStringReplace(debugInfo.table.localNode.nodeId, nodeName); log.AddStringReplace(nodePeerId, nodeName);
log.AddStringReplace(debugInfo.table.localNode.nodeId, nodeName);
Version = debugInfo.codex; Version = debugInfo.codex;
} }

View File

@ -1,5 +1,6 @@
using CodexPlugin; using CodexPlugin;
using NUnit.Framework; using NUnit.Framework;
using Utils;
namespace CodexTests.PeerDiscoveryTests namespace CodexTests.PeerDiscoveryTests
{ {
@ -18,23 +19,33 @@ namespace CodexTests.PeerDiscoveryTests
} }
private void AssertRoutingTable() private void AssertRoutingTable()
{
Time.Retry(CheckRoutingTable, 3, nameof(CheckRoutingTable));
}
private void CheckRoutingTable()
{ {
var all = GetAllOnlineCodexNodes(); var all = GetAllOnlineCodexNodes();
var allNodeIds = all.Select(n => n.GetDebugInfo().table.localNode.nodeId).ToArray(); var allResponses = all.Select(n => n.GetDebugInfo()).ToArray();
var errors = all.Select(n => AreAllPresent(n, allNodeIds)).Where(s => !string.IsNullOrEmpty(s)).ToArray();
var errors = new List<string>();
foreach (var response in allResponses)
{
var error = AreAllPresent(response, allResponses);
if (!string.IsNullOrEmpty(error)) errors.Add(error);
}
if (errors.Any()) if (errors.Any())
{ {
Assert.Fail(string.Join(Environment.NewLine, errors)); 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 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))) if (!expectedIds.All(ex => knownIds.Contains(ex)))
{ {
@ -43,5 +54,10 @@ namespace CodexTests.PeerDiscoveryTests
return string.Empty; return string.Empty;
} }
private CodexDebugResponse[] GetAllOtherResponses(CodexDebugResponse exclude, CodexDebugResponse[] allResponses)
{
return allResponses.Where(r => r.id != exclude.id).ToArray();
}
} }
} }