Improves retrying in peer test helper

This commit is contained in:
benbierens 2023-05-11 13:59:53 +02:00
parent 38d5b172f4
commit f7e7849460
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 15 additions and 32 deletions

View File

@ -15,21 +15,18 @@ namespace Tests.PeerDiscoveryTests
public static void AssertFullyConnected(BaseLog? log = null, params IOnlineCodexNode[] nodes) public static void AssertFullyConnected(BaseLog? log = null, params IOnlineCodexNode[] nodes)
{ {
Time.Retry(() => var entries = nodes.Select(n => new Entry(n)).ToArray();
var failureMessags = new List<string>();
for (var x = 0; x < entries.Length; x++)
{ {
var entries = nodes.Select(n => new Entry(n)).ToArray(); for (var y = x + 1; y < entries.Length; y++)
var failureMessags = new List<string>();
for (var x = 0; x < entries.Length; x++)
{ {
for (var y = x + 1; y < entries.Length; y++) AssertKnowEachother(failureMessags, entries[x], entries[y], log);
{
AssertKnowEachother(failureMessags, entries[x], entries[y], log);
}
} }
}
CollectionAssert.IsEmpty(failureMessags); CollectionAssert.IsEmpty(failureMessags);
});
} }
private static void AssertKnowEachother(List<string> failureMessags, Entry a, Entry b, BaseLog? log) private static void AssertKnowEachother(List<string> failureMessags, Entry a, Entry b, BaseLog? log)
@ -44,7 +41,7 @@ namespace Tests.PeerDiscoveryTests
try try
{ {
var response = a.Node.GetDebugPeer(peerId); var response = GetDebugPeer(a.Node, peerId);
if (string.IsNullOrEmpty(response.peerId) || !response.addresses.Any()) if (string.IsNullOrEmpty(response.peerId) || !response.addresses.Any())
{ {
failureMessags.Add($"{a.Response.id} did not know peer {peerId}"); failureMessags.Add($"{a.Response.id} did not know peer {peerId}");
@ -54,29 +51,15 @@ namespace Tests.PeerDiscoveryTests
log.Log($"{a.Response.id} knows {peerId}."); log.Log($"{a.Response.id} knows {peerId}.");
} }
} }
catch (Exception e) catch
{ {
failureMessags.Add($"{a.Response.id} was unable to get 'debug/peer/{peerId}'. {e}"); failureMessags.Add($"{a.Response.id} was unable to get 'debug/peer/{peerId}'.");
} }
}
////var enginePeers = string.Join(",", a.enginePeers.Select(p => p.peerId)); private static CodexDebugPeerResponse GetDebugPeer(IOnlineCodexNode node, string peerId)
////var switchPeers = string.Join(",", a.switchPeers.Select(p => p.peerId)); {
//var tableNodes = string.Join(",", a.table.nodes.Select(n => n.nodeId)); return Time.Retry(() => node.GetDebugPeer(peerId));
//var success = a.table.nodes.Any(n => n.nodeId == b.table.localNode.nodeId);
//if (log != null)
//{
// 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.");
//if (!success)
//{
// failureMessags.Add($"{a.table.localNode.nodeId} was looking for '{b.table.localNode.nodeId}' in table-nodes [{tableNodes}] but it was not found.");
//}
} }
public class Entry public class Entry