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)
{
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)
{
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)

View File

@ -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;
}

View File

@ -1,5 +1,6 @@
using CodexPlugin;
using NUnit.Framework;
using Utils;
namespace CodexTests.PeerDiscoveryTests
{
@ -19,10 +20,20 @@ namespace CodexTests.PeerDiscoveryTests
private void AssertRoutingTable()
{
var all = GetAllOnlineCodexNodes();
var allNodeIds = all.Select(n => n.GetDebugInfo().table.localNode.nodeId).ToArray();
Time.Retry(CheckRoutingTable, 3, nameof(CheckRoutingTable));
}
var errors = all.Select(n => AreAllPresent(n, allNodeIds)).Where(s => !string.IsNullOrEmpty(s)).ToArray();
private void CheckRoutingTable()
{
var all = GetAllOnlineCodexNodes();
var allResponses = all.Select(n => n.GetDebugInfo()).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())
{
@ -30,11 +41,11 @@ namespace CodexTests.PeerDiscoveryTests
}
}
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();
}
}
}