Peer table test

This commit is contained in:
Ben 2024-11-21 14:34:13 +01:00
parent e743a1cd7b
commit 339cf2b824
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
1 changed files with 50 additions and 2 deletions

View File

@ -1,12 +1,60 @@
using System; using CodexPlugin;
using CodexTests;
using NUnit.Framework;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Utils;
namespace CodexReleaseTests.NodeTests namespace CodexReleaseTests.NodeTests
{ {
internal class PeerTableTests [TestFixture]
public class PeerTableTests : AutoBootstrapDistTest
{ {
[Test]
public void PeerTableCompleteness()
{
var nodes = StartCodex(10);
var retry = new Retry(
description: nameof(PeerTableCompleteness),
maxTimeout: TimeSpan.FromMinutes(2),
sleepAfterFail: TimeSpan.FromSeconds(5),
onFail: f => { }
);
retry.Run(() => AssertAllNodesSeeEachOther(nodes));
}
private void AssertAllNodesSeeEachOther(ICodexNodeGroup nodes)
{
foreach (var a in nodes)
{
AssertHasSeenAllOtherNodes(a, nodes);
}
}
private void AssertHasSeenAllOtherNodes(ICodexNode node, ICodexNodeGroup nodes)
{
var localNode = node.GetDebugInfo().Table.LocalNode;
foreach (var other in nodes)
{
var info = other.GetDebugInfo();
if (info.Table.LocalNode.PeerId != localNode.PeerId)
{
AssertContainsPeerId(info, localNode.PeerId);
}
}
}
private void AssertContainsPeerId(DebugInfo info, string peerId)
{
var entry = info.Table.Nodes.SingleOrDefault(n => n.PeerId == peerId);
if (entry == null) throw new Exception("Table entry not found.");
if (!entry.Seen) throw new Exception("Peer not seen.");
}
} }
} }