From 96ff3c38bb9110d9425624382c2844f41ff9921e Mon Sep 17 00:00:00 2001 From: benbierens Date: Sun, 12 Nov 2023 10:36:48 +0100 Subject: [PATCH] Adds test for routing table checks. --- Tests/CodexContinuousTests/Tests/PeersTest.cs | 5 +- Tests/CodexTests/CodexDistTest.cs | 2 +- .../FullyConnectedDownloadTests.cs | 3 +- .../Helpers/FullConnectivityHelper.cs | 2 +- .../Helpers/PeerConnectionTestHelpers.cs | 4 +- .../Helpers/PeerDownloadTestHelpers.cs | 4 +- .../LayeredDiscoveryTests.cs | 3 +- .../PeerDiscoveryTests/PeerDiscoveryTests.cs | 3 +- .../PeerDiscoveryTests/RoutingTableTests.cs | 47 +++++++++++++++++++ .../PeerConnectivityChecker.cs | 2 +- 10 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs diff --git a/Tests/CodexContinuousTests/Tests/PeersTest.cs b/Tests/CodexContinuousTests/Tests/PeersTest.cs index 8d5d08b3..38d2f4f7 100644 --- a/Tests/CodexContinuousTests/Tests/PeersTest.cs +++ b/Tests/CodexContinuousTests/Tests/PeersTest.cs @@ -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 { diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index d651c658..4d6dab23 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -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; diff --git a/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs b/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs index 2f0a4451..0acd7804 100644 --- a/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs +++ b/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs @@ -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 diff --git a/Tests/CodexTests/Helpers/FullConnectivityHelper.cs b/Tests/CodexTests/Helpers/FullConnectivityHelper.cs index e0ef335a..1504c78e 100644 --- a/Tests/CodexTests/Helpers/FullConnectivityHelper.cs +++ b/Tests/CodexTests/Helpers/FullConnectivityHelper.cs @@ -2,7 +2,7 @@ using Logging; using NUnit.Framework; -namespace DistTestCore.Helpers +namespace CodexTests.Helpers { public interface IFullConnectivityImplementation { diff --git a/Tests/CodexTests/Helpers/PeerConnectionTestHelpers.cs b/Tests/CodexTests/Helpers/PeerConnectionTestHelpers.cs index 5d428322..d644296a 100644 --- a/Tests/CodexTests/Helpers/PeerConnectionTestHelpers.cs +++ b/Tests/CodexTests/Helpers/PeerConnectionTestHelpers.cs @@ -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 { diff --git a/Tests/CodexTests/Helpers/PeerDownloadTestHelpers.cs b/Tests/CodexTests/Helpers/PeerDownloadTestHelpers.cs index 6ad178f2..fab2a23c 100644 --- a/Tests/CodexTests/Helpers/PeerDownloadTestHelpers.cs +++ b/Tests/CodexTests/Helpers/PeerDownloadTestHelpers.cs @@ -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 { diff --git a/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs b/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs index 310b6aa5..4c8a3b3b 100644 --- a/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs +++ b/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs @@ -1,8 +1,7 @@ using CodexPlugin; -using CodexTests; using NUnit.Framework; -namespace Tests.PeerDiscoveryTests +namespace CodexTests.PeerDiscoveryTests { [TestFixture] public class LayeredDiscoveryTests : CodexDistTest diff --git a/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs b/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs index 9eca0c68..57f27a3a 100644 --- a/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs +++ b/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs @@ -1,9 +1,8 @@ using CodexContractsPlugin; -using CodexTests; using GethPlugin; using NUnit.Framework; -namespace Tests.PeerDiscoveryTests +namespace CodexTests.PeerDiscoveryTests { [TestFixture] public class PeerDiscoveryTests : AutoBootstrapDistTest diff --git a/Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs b/Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs new file mode 100644 index 00000000..8f753ae3 --- /dev/null +++ b/Tests/CodexTests/PeerDiscoveryTests/RoutingTableTests.cs @@ -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; + } + } +} diff --git a/Tools/CodexNetDeployer/PeerConnectivityChecker.cs b/Tools/CodexNetDeployer/PeerConnectivityChecker.cs index 87bdc316..06cb1a5d 100644 --- a/Tools/CodexNetDeployer/PeerConnectivityChecker.cs +++ b/Tools/CodexNetDeployer/PeerConnectivityChecker.cs @@ -1,4 +1,4 @@ -using DistTestCore.Helpers; +using CodexTests.Helpers; using Logging; namespace CodexNetDeployer