Adds assert that nodes have correct addresses in their table of peers.

This commit is contained in:
benbierens 2023-05-29 08:35:46 +02:00
parent 025b03e678
commit ab7a334987
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
5 changed files with 48 additions and 17 deletions

View File

@ -66,8 +66,8 @@ namespace DistTestCore.Codex
var nodePeerId = debugInfo.id;
var nodeName = Container.Name;
log.AddStringReplace(nodePeerId, $"___{nodeName}___");
log.AddStringReplace(debugInfo.table.localNode.nodeId, $"__{nodeName}__");
log.AddStringReplace(nodePeerId, nodeName);
log.AddStringReplace(debugInfo.table.localNode.nodeId, nodeName);
}
catch (Exception e)
{
@ -107,6 +107,7 @@ namespace DistTestCore.Codex
public string nodeId { get; set; } = string.Empty;
public string peerId { get; set; } = string.Empty;
public string record { get; set; } = string.Empty;
public string address { get; set; } = string.Empty;
public bool seen { get; set; }
}

View File

@ -13,6 +13,7 @@ namespace DistTestCore.Codex
public const string DockerImage = "thatbenbierens/codexlocal:latest";
#endif
public const string MetricsPortTag = "metrics_port";
public const string DiscoveryPortTag = "discovery-port";
protected override string Image => DockerImage;
@ -22,7 +23,7 @@ namespace DistTestCore.Codex
AddExposedPortAndVar("API_PORT");
AddEnvVar("DATA_DIR", $"datadir{ContainerNumber}");
AddInternalPortAndVar("DISC_PORT");
AddInternalPortAndVar("DISC_PORT", DiscoveryPortTag);
var listenPort = AddInternalPort();
AddEnvVar("LISTEN_ADDRS", $"/ip4/0.0.0.0/tcp/{listenPort.Number}");

View File

@ -1,5 +1,6 @@
using DistTestCore;
using NUnit.Framework;
using Utils;
namespace Tests.PeerDiscoveryTests
{
@ -33,6 +34,7 @@ namespace Tests.PeerDiscoveryTests
[TestCase(5)]
[TestCase(10)]
[TestCase(20)]
[TestCase(50)]
public void NodeChainTest(int chainLength)
{
var node = SetupCodexNode();
@ -42,6 +44,12 @@ namespace Tests.PeerDiscoveryTests
}
AssertAllNodesConnected();
for (int i = 0; i < 5; i++)
{
Time.Sleep(TimeSpan.FromSeconds(30));
AssertAllNodesConnected();
}
}
private void AssertAllNodesConnected()

View File

@ -46,8 +46,7 @@ namespace Tests.PeerDiscoveryTests
AssertAllNodesConnected();
}
// Retain for a while
for (int i = 0; i < 10; i++)
for (int i = 0; i < 5; i++)
{
Time.Sleep(TimeSpan.FromSeconds(30));
AssertAllNodesConnected();

View File

@ -52,18 +52,22 @@ namespace Tests.PeerDiscoveryTests
if (pair.Success)
{
pairs.Remove(pair);
if (log != null) log.Log(pair.GetMessage());
}
else
{
pair.IncreaseTimeout();
}
}
}
private static Entry[] CreateEntries(IOnlineCodexNode[] nodes)
{
return nodes.Select(n => new Entry(n)).ToArray();
var entries = nodes.Select(n => new Entry(n)).ToArray();
var incorrectDiscoveryEndpoints = entries.SelectMany(e => e.GetInCorrectDiscoveryEndpoints(entries)).ToArray();
if (incorrectDiscoveryEndpoints.Any())
{
Assert.Fail("Some nodes contain peer records with incorrect discovery ip/port information: " +
string.Join(Environment.NewLine, incorrectDiscoveryEndpoints));
}
return entries;
}
private static List<Pair> CreatePairs(Entry[] entries)
@ -92,11 +96,34 @@ namespace Tests.PeerDiscoveryTests
public IOnlineCodexNode Node { get ; }
public CodexDebugResponse Response { get; }
public IEnumerable<string> GetInCorrectDiscoveryEndpoints(Entry[] allEntries)
{
foreach (var peer in Response.table.nodes)
{
var expected = GetExpectedDiscoveryEndpoint(allEntries, peer);
if (expected != peer.address)
{
yield return $"Node:{Node.GetName()} has incorrect peer table entry. Was: '{peer.address}', expected: '{expected}'";
}
}
}
private static string GetExpectedDiscoveryEndpoint(Entry[] allEntries, CodexDebugTableNodeResponse node)
{
var peer = allEntries.SingleOrDefault(e => e.Response.table.localNode.peerId == node.peerId);
if (peer == null) return $"peerId: {node.peerId} is not known.";
var n = (OnlineCodexNode)peer.Node;
var ip = n.CodexAccess.Container.Pod.Ip;
var discPort = n.CodexAccess.Container.Recipe.GetPortByTag(CodexContainerRecipe.DiscoveryPortTag);
return $"{ip}:{discPort.Number}";
}
}
public class Pair
{
private TimeSpan timeout = TimeSpan.FromSeconds(60);
private readonly TimeSpan timeout = TimeSpan.FromSeconds(60);
private TimeSpan aToBTime = TimeSpan.FromSeconds(0);
private TimeSpan bToATime = TimeSpan.FromSeconds(0);
@ -124,11 +151,6 @@ namespace Tests.PeerDiscoveryTests
return GetResultMessage() + GetTimePostfix();
}
public void IncreaseTimeout()
{
//timeout *= 2;
}
private string GetResultMessage()
{
var aName = A.Response.id;