Moves routing table test into peerDiscovery tests.
This commit is contained in:
parent
496f8fa370
commit
6636ef3ac1
|
@ -1,4 +1,5 @@
|
|||
using CodexContractsPlugin;
|
||||
using CodexPlugin;
|
||||
using GethPlugin;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
@ -48,7 +49,45 @@ namespace CodexTests.PeerDiscoveryTests
|
|||
|
||||
private void AssertAllNodesConnected()
|
||||
{
|
||||
CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes());
|
||||
var allNodes = GetAllOnlineCodexNodes();
|
||||
CreatePeerConnectionTestHelpers().AssertFullyConnected(allNodes);
|
||||
CheckRoutingTable(allNodes);
|
||||
}
|
||||
|
||||
private void CheckRoutingTable(IEnumerable<ICodexNode> allNodes)
|
||||
{
|
||||
var allResponses = allNodes.Select(n => n.GetDebugInfo()).ToArray();
|
||||
|
||||
var errors = new List<string>();
|
||||
foreach (var response in allResponses)
|
||||
{
|
||||
var error = AreAllPresent(response, allResponses);
|
||||
if (!string.IsNullOrEmpty(error)) errors.Add(error);
|
||||
}
|
||||
|
||||
if (errors.Any())
|
||||
{
|
||||
Assert.Fail(string.Join(Environment.NewLine, errors));
|
||||
}
|
||||
}
|
||||
|
||||
private string AreAllPresent(CodexDebugResponse info, CodexDebugResponse[] allResponses)
|
||||
{
|
||||
var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray();
|
||||
var allOthers = GetAllOtherResponses(info, allResponses);
|
||||
var expectedIds = allOthers.Select(i => i.table.localNode.nodeId).ToArray();
|
||||
|
||||
if (!expectedIds.All(ex => knownIds.Contains(ex)))
|
||||
{
|
||||
return $"Node {info.id}: Not all of '{string.Join(",", expectedIds)}' were present in routing table: '{string.Join(",", knownIds)}'";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private CodexDebugResponse[] GetAllOtherResponses(CodexDebugResponse exclude, CodexDebugResponse[] allResponses)
|
||||
{
|
||||
return allResponses.Where(r => r.id != exclude.id).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
using CodexPlugin;
|
||||
using NUnit.Framework;
|
||||
using Utils;
|
||||
|
||||
namespace CodexTests.PeerDiscoveryTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RoutingTableTests : AutoBootstrapDistTest
|
||||
{
|
||||
[TestCase(2)]
|
||||
[TestCase(3)]
|
||||
[TestCase(10)]
|
||||
[TestCase(20)]
|
||||
public void VariableNodes(int number)
|
||||
{
|
||||
AddCodex(number);
|
||||
|
||||
AssertRoutingTable();
|
||||
}
|
||||
|
||||
private void AssertRoutingTable()
|
||||
{
|
||||
Time.Retry(CheckRoutingTable, 3, nameof(CheckRoutingTable));
|
||||
}
|
||||
|
||||
private void CheckRoutingTable()
|
||||
{
|
||||
var all = GetAllOnlineCodexNodes();
|
||||
var allResponses = all.Select(n => n.GetDebugInfo()).ToArray();
|
||||
|
||||
var errors = new List<string>();
|
||||
foreach (var response in allResponses)
|
||||
{
|
||||
var error = AreAllPresent(response, allResponses);
|
||||
if (!string.IsNullOrEmpty(error)) errors.Add(error);
|
||||
}
|
||||
|
||||
if (errors.Any())
|
||||
{
|
||||
Assert.Fail(string.Join(Environment.NewLine, errors));
|
||||
}
|
||||
}
|
||||
|
||||
private string AreAllPresent(CodexDebugResponse info, CodexDebugResponse[] allResponses)
|
||||
{
|
||||
var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray();
|
||||
var allOthers = GetAllOtherResponses(info, allResponses);
|
||||
var expectedIds = allOthers.Select(i => i.table.localNode.nodeId).ToArray();
|
||||
|
||||
if (!expectedIds.All(ex => knownIds.Contains(ex)))
|
||||
{
|
||||
return $"Not all of '{string.Join(",", expectedIds)}' were present in routing table: '{string.Join(",", knownIds)}'";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private CodexDebugResponse[] GetAllOtherResponses(CodexDebugResponse exclude, CodexDebugResponse[] allResponses)
|
||||
{
|
||||
return allResponses.Where(r => r.id != exclude.id).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue