2023-08-29 14:08:40 +00:00
|
|
|
|
using DistTestCore.Codex;
|
2023-08-30 06:33:38 +00:00
|
|
|
|
using DistTestCore.Helpers;
|
2023-08-29 14:08:40 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace ContinuousTests.Tests
|
|
|
|
|
{
|
|
|
|
|
public class PeersTest : ContinuousTest
|
|
|
|
|
{
|
|
|
|
|
public override int RequiredNumberOfNodes => -1;
|
2023-09-04 07:19:04 +00:00
|
|
|
|
public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(2);
|
2023-08-29 14:08:40 +00:00
|
|
|
|
public override TestFailMode TestFailMode => TestFailMode.AlwaysRunAllMoments;
|
|
|
|
|
|
|
|
|
|
[TestMoment(t: 0)]
|
2023-08-30 06:33:38 +00:00
|
|
|
|
public void CheckConnectivity()
|
|
|
|
|
{
|
|
|
|
|
var checker = new PeerConnectionTestHelpers(Log);
|
|
|
|
|
checker.AssertFullyConnected(Nodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMoment(t: 10)]
|
2023-08-29 14:08:40 +00:00
|
|
|
|
public void CheckRoutingTables()
|
|
|
|
|
{
|
2023-08-30 06:33:38 +00:00
|
|
|
|
var allInfos = Nodes.Select(n =>
|
|
|
|
|
{
|
|
|
|
|
var info = n.GetDebugInfo();
|
|
|
|
|
Log.Log($"{n.GetName()} = {info.table.localNode.nodeId}");
|
2023-08-30 06:53:09 +00:00
|
|
|
|
Log.AddStringReplace(info.table.localNode.nodeId, n.GetName());
|
2023-08-30 06:33:38 +00:00
|
|
|
|
return info;
|
|
|
|
|
}).ToArray();
|
2023-08-29 14:08:40 +00:00
|
|
|
|
|
2023-08-30 06:33:38 +00:00
|
|
|
|
var allIds = allInfos.Select(i => i.table.localNode.nodeId).ToArray();
|
2023-08-29 14:08:40 +00:00
|
|
|
|
var errors = Nodes.Select(n => AreAllPresent(n, allIds)).Where(s => !string.IsNullOrEmpty(s)).ToArray();
|
|
|
|
|
|
|
|
|
|
if (errors.Any())
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail(string.Join(Environment.NewLine, errors));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string AreAllPresent(CodexAccess n, string[] allIds)
|
|
|
|
|
{
|
|
|
|
|
var info = n.GetDebugInfo();
|
|
|
|
|
var known = info.table.nodes.Select(n => n.nodeId).ToArray();
|
|
|
|
|
var expected = allIds.Where(i => i != info.table.localNode.nodeId).ToArray();
|
|
|
|
|
|
|
|
|
|
if (!expected.All(ex => known.Contains(ex)))
|
|
|
|
|
{
|
2023-08-30 06:33:38 +00:00
|
|
|
|
var nl = Environment.NewLine;
|
2023-08-30 06:53:09 +00:00
|
|
|
|
return $"{nl}At node '{info.table.localNode.nodeId}'{nl}" +
|
|
|
|
|
$"Not all of{nl}'{string.Join(",", expected)}'{nl}" +
|
|
|
|
|
$"were present in routing table:{nl}'{string.Join(",", known)}'";
|
2023-08-29 14:08:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|