2
0
mirror of synced 2025-01-12 17:44:08 +00:00

Fixes PeerTableTests of CodexReleaseTests

This commit is contained in:
Ben 2024-12-02 10:34:09 +01:00
parent 86d5ab22f6
commit d7c3fe6c5f
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
2 changed files with 12 additions and 38 deletions

View File

@ -14,7 +14,7 @@ namespace CodexPlugin
{
string GetName();
string GetPeerId();
DebugInfo GetDebugInfo();
DebugInfo GetDebugInfo(bool log = false);
string GetSpr();
DebugPeer GetDebugPeer(string peerId);
ContentId UploadFile(TrackedFile file);
@ -123,11 +123,14 @@ namespace CodexPlugin
return peerId;
}
public DebugInfo GetDebugInfo()
public DebugInfo GetDebugInfo(bool log = false)
{
var debugInfo = CodexAccess.GetDebugInfo();
var known = string.Join(",", debugInfo.Table.Nodes.Select(n => n.PeerId));
Log($"Got DebugInfo with id: {debugInfo.Id}. This node knows: [{known}]");
if (log)
{
var known = string.Join(",", debugInfo.Table.Nodes.Select(n => n.PeerId));
Log($"Got DebugInfo with id: {debugInfo.Id}. This node knows: [{known}]");
}
return debugInfo;
}

View File

@ -1,5 +1,6 @@
using CodexPlugin;
using CodexTests;
using CodexTests.Helpers;
using NUnit.Framework;
using System;
using System.Collections.Generic;
@ -18,43 +19,13 @@ namespace CodexReleaseTests.NodeTests
{
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));
AssertAllNodesSeeEachOther(nodes.Concat([BootstrapNode!]));
}
private void AssertAllNodesSeeEachOther(ICodexNodeGroup nodes)
private void AssertAllNodesSeeEachOther(IEnumerable<ICodexNode> 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.");
var helper = new PeerConnectionTestHelpers(GetTestLog());
helper.AssertFullyConnected(nodes);
}
}
}