2023-05-10 07:55:36 +00:00
|
|
|
|
using DistTestCore.Codex;
|
2023-08-24 08:59:11 +00:00
|
|
|
|
using Logging;
|
2023-07-18 14:07:52 +00:00
|
|
|
|
using static DistTestCore.Helpers.FullConnectivityHelper;
|
2023-05-10 07:55:36 +00:00
|
|
|
|
|
2023-05-29 07:13:38 +00:00
|
|
|
|
namespace DistTestCore.Helpers
|
2023-05-10 07:55:36 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public class PeerConnectionTestHelpers : IFullConnectivityImplementation
|
2023-05-10 07:55:36 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
private readonly FullConnectivityHelper helper;
|
2023-05-18 08:42:04 +00:00
|
|
|
|
|
2023-08-24 08:59:11 +00:00
|
|
|
|
public PeerConnectionTestHelpers(BaseLog log)
|
2023-05-10 07:55:36 +00:00
|
|
|
|
{
|
2023-08-24 08:59:11 +00:00
|
|
|
|
helper = new FullConnectivityHelper(log, this);
|
2023-05-10 07:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 07:13:38 +00:00
|
|
|
|
public void AssertFullyConnected(IEnumerable<IOnlineCodexNode> nodes)
|
2023-08-24 09:32:32 +00:00
|
|
|
|
{
|
|
|
|
|
AssertFullyConnected(nodes.Select(n => ((OnlineCodexNode)n).CodexAccess));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AssertFullyConnected(IEnumerable<CodexAccess> nodes)
|
2023-05-29 07:13:38 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
helper.AssertFullyConnected(nodes);
|
2023-05-10 07:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public string Description()
|
2023-05-10 07:55:36 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return "Peer Discovery";
|
2023-05-10 07:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public string ValidateEntry(Entry entry, Entry[] allEntries)
|
2023-05-12 07:11:05 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var result = string.Empty;
|
|
|
|
|
foreach (var peer in entry.Response.table.nodes)
|
2023-05-12 07:11:05 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var expected = GetExpectedDiscoveryEndpoint(allEntries, peer);
|
|
|
|
|
if (expected != peer.address)
|
2023-05-12 08:48:12 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
result += $"Node:{entry.Node.GetName()} has incorrect peer table entry. Was: '{peer.address}', expected: '{expected}'. ";
|
2023-05-18 08:42:04 +00:00
|
|
|
|
}
|
2023-05-12 07:11:05 +00:00
|
|
|
|
}
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return result;
|
2023-05-12 07:11:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
public PeerConnectionState Check(Entry from, Entry to)
|
2023-05-10 07:55:36 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var peerId = to.Response.id;
|
2023-05-29 07:13:38 +00:00
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var response = from.Node.GetDebugPeer(peerId);
|
|
|
|
|
if (!response.IsPeerFound)
|
2023-05-29 06:35:46 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return PeerConnectionState.NoConnection;
|
2023-05-29 06:35:46 +00:00
|
|
|
|
}
|
2023-07-18 14:07:52 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(response.peerId) && response.addresses.Any())
|
2023-05-10 07:55:36 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return PeerConnectionState.Connection;
|
2023-05-11 10:44:53 +00:00
|
|
|
|
}
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return PeerConnectionState.Unknown;
|
2023-05-11 10:44:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 14:07:52 +00:00
|
|
|
|
private static string GetExpectedDiscoveryEndpoint(Entry[] allEntries, CodexDebugTableNodeResponse node)
|
2023-05-29 07:13:38 +00:00
|
|
|
|
{
|
2023-07-18 14:07:52 +00:00
|
|
|
|
var peer = allEntries.SingleOrDefault(e => e.Response.table.localNode.peerId == node.peerId);
|
|
|
|
|
if (peer == null) return $"peerId: {node.peerId} is not known.";
|
2023-05-29 06:35:46 +00:00
|
|
|
|
|
2023-08-24 09:32:32 +00:00
|
|
|
|
var ip = peer.Node.Container.Pod.PodInfo.Ip;
|
|
|
|
|
var discPort = peer.Node.Container.Recipe.GetPortByTag(CodexContainerRecipe.DiscoveryPortTag);
|
2023-07-18 14:07:52 +00:00
|
|
|
|
return $"{ip}:{discPort.Number}";
|
2023-05-12 08:48:12 +00:00
|
|
|
|
}
|
2023-05-10 07:55:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|