cs-codex-dist-tests/ContinuousTests/Tests/PeersTest.cs

55 lines
1.8 KiB
C#
Raw Normal View History

using DistTestCore.Codex;
2023-08-30 06:33:38 +00:00
using DistTestCore.Helpers;
using NUnit.Framework;
namespace ContinuousTests.Tests
{
public class PeersTest : ContinuousTest
{
public override int RequiredNumberOfNodes => -1;
public override TimeSpan RunTestEvery => TimeSpan.FromSeconds(30);
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)]
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}");
return info;
}).ToArray();
2023-08-30 06:33:38 +00:00
var allIds = allInfos.Select(i => i.table.localNode.nodeId).ToArray();
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;
return $"Not all of{nl}'{string.Join(",", expected)}'{nl}were present in routing table:{nl}'{string.Join(",", known)}'";
}
return string.Empty;
}
}
}