Adds test for routing table checks.

This commit is contained in:
benbierens 2023-11-12 10:36:48 +01:00
parent ed56d9edcc
commit 96ff3c38bb
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
10 changed files with 60 additions and 15 deletions

View File

@ -1,8 +1,9 @@
using CodexPlugin;
using DistTestCore.Helpers;
using CodexTests.Helpers;
using ContinuousTests;
using NUnit.Framework;
namespace ContinuousTests.Tests
namespace CodexContinuousTests.Tests
{
public class PeersTest : ContinuousTest
{

View File

@ -1,11 +1,11 @@
using CodexContractsPlugin;
using CodexNetDeployer;
using CodexPlugin;
using CodexTests.Helpers;
using Core;
using DistTestCore;
using DistTestCore.Helpers;
using DistTestCore.Logs;
using GethPlugin;
using NUnit.Framework;
using NUnit.Framework.Constraints;

View File

@ -1,10 +1,9 @@
using CodexContractsPlugin;
using CodexTests;
using GethPlugin;
using NUnit.Framework;
using Utils;
namespace Tests.DownloadConnectivityTests
namespace CodexTests.DownloadConnectivityTests
{
[TestFixture]
public class FullyConnectedDownloadTests : AutoBootstrapDistTest

View File

@ -2,7 +2,7 @@
using Logging;
using NUnit.Framework;
namespace DistTestCore.Helpers
namespace CodexTests.Helpers
{
public interface IFullConnectivityImplementation
{

View File

@ -1,8 +1,8 @@
using CodexPlugin;
using Logging;
using static DistTestCore.Helpers.FullConnectivityHelper;
using static CodexTests.Helpers.FullConnectivityHelper;
namespace DistTestCore.Helpers
namespace CodexTests.Helpers
{
public class PeerConnectionTestHelpers : IFullConnectivityImplementation
{

View File

@ -2,9 +2,9 @@
using FileUtils;
using Logging;
using Utils;
using static DistTestCore.Helpers.FullConnectivityHelper;
using static CodexTests.Helpers.FullConnectivityHelper;
namespace DistTestCore.Helpers
namespace CodexTests.Helpers
{
public class PeerDownloadTestHelpers : IFullConnectivityImplementation
{

View File

@ -1,8 +1,7 @@
using CodexPlugin;
using CodexTests;
using NUnit.Framework;
namespace Tests.PeerDiscoveryTests
namespace CodexTests.PeerDiscoveryTests
{
[TestFixture]
public class LayeredDiscoveryTests : CodexDistTest

View File

@ -1,9 +1,8 @@
using CodexContractsPlugin;
using CodexTests;
using GethPlugin;
using NUnit.Framework;
namespace Tests.PeerDiscoveryTests
namespace CodexTests.PeerDiscoveryTests
{
[TestFixture]
public class PeerDiscoveryTests : AutoBootstrapDistTest

View File

@ -0,0 +1,47 @@
using CodexPlugin;
using NUnit.Framework;
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()
{
var all = GetAllOnlineCodexNodes();
var allNodeIds = all.Select(n => n.GetDebugInfo().table.localNode.nodeId).ToArray();
var errors = all.Select(n => AreAllPresent(n, allNodeIds)).Where(s => !string.IsNullOrEmpty(s)).ToArray();
if (errors.Any())
{
Assert.Fail(string.Join(Environment.NewLine, errors));
}
}
private string AreAllPresent(ICodexNode n, string[] allNodesIds)
{
var info = n.GetDebugInfo();
var knownIds = info.table.nodes.Select(n => n.nodeId).ToArray();
var expectedIds = allNodesIds.Where(id => id != info.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;
}
}
}

View File

@ -1,4 +1,4 @@
using DistTestCore.Helpers;
using CodexTests.Helpers;
using Logging;
namespace CodexNetDeployer