From 8f61c46ff01c12e37b57a17a2d03600054ecd09e Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 29 Aug 2023 16:08:40 +0200 Subject: [PATCH] Adds simple test to ensure routing table is correctly filled. --- ContinuousTests/SingleTestRun.cs | 2 + ContinuousTests/StartupChecker.cs | 11 +++- ContinuousTests/Tests/PeersTest.cs | 39 ++++++++++++++ Tests/BasicTests/ContinuousSubstitute.cs | 65 ++++++++++++++++++++++-- 4 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 ContinuousTests/Tests/PeersTest.cs diff --git a/ContinuousTests/SingleTestRun.cs b/ContinuousTests/SingleTestRun.cs index bbc4888c..e2680647 100644 --- a/ContinuousTests/SingleTestRun.cs +++ b/ContinuousTests/SingleTestRun.cs @@ -209,6 +209,8 @@ namespace ContinuousTests private RunningContainer[] SelectRandomContainers(int number) { + if (number == -1) return config.CodexDeployment.CodexContainers; + var containers = config.CodexDeployment.CodexContainers.ToList(); var result = new RunningContainer[number]; for (var i = 0; i < number; i++) diff --git a/ContinuousTests/StartupChecker.cs b/ContinuousTests/StartupChecker.cs index f6a470cd..5986fa5e 100644 --- a/ContinuousTests/StartupChecker.cs +++ b/ContinuousTests/StartupChecker.cs @@ -156,9 +156,16 @@ namespace ContinuousTests { foreach (var test in tests) { - if (test.RequiredNumberOfNodes > config.CodexDeployment.CodexContainers.Length) + if (test.RequiredNumberOfNodes != -1) { - errors.Add($"Test '{test.Name}' requires {test.RequiredNumberOfNodes} nodes. Deployment only has {config.CodexDeployment.CodexContainers.Length}"); + if (test.RequiredNumberOfNodes < 1) + { + errors.Add($"Test '{test.Name}' requires {test.RequiredNumberOfNodes} nodes. Test must require > 0 nodes, or -1 to select all nodes."); + } + else if (test.RequiredNumberOfNodes > config.CodexDeployment.CodexContainers.Length) + { + errors.Add($"Test '{test.Name}' requires {test.RequiredNumberOfNodes} nodes. Deployment only has {config.CodexDeployment.CodexContainers.Length}"); + } } } } diff --git a/ContinuousTests/Tests/PeersTest.cs b/ContinuousTests/Tests/PeersTest.cs new file mode 100644 index 00000000..13c54d9e --- /dev/null +++ b/ContinuousTests/Tests/PeersTest.cs @@ -0,0 +1,39 @@ +using DistTestCore.Codex; +using NUnit.Framework; + +namespace ContinuousTests.Tests +{ + public class PeersTest : ContinuousTest + { + public override int RequiredNumberOfNodes => -1; + public override TimeSpan RunTestEvery => TimeSpan.FromSeconds(30); + public override TestFailMode TestFailMode => TestFailMode.AlwaysRunAllMoments; + + [TestMoment(t: 0)] + public void CheckRoutingTables() + { + var allIds = Nodes.Select(n => n.GetDebugInfo().table.localNode.nodeId).ToArray(); + + var errors = Nodes.Select(n => AreAllPresent(n, allIds)).Where(s => !string.IsNullOrEmpty(s)).ToArray(); + + if (errors.Any()) + { + Assert.Fail(string.Join(Environment.NewLine, errors)); + } + } + + private string AreAllPresent(CodexAccess n, string[] allIds) + { + var info = n.GetDebugInfo(); + var known = info.table.nodes.Select(n => n.nodeId).ToArray(); + var expected = allIds.Where(i => i != info.table.localNode.nodeId).ToArray(); + + if (!expected.All(ex => known.Contains(ex))) + { + return $"Not all of '{string.Join(",", expected)}' were present in routing table: '{string.Join(",", known)}'"; + } + + return string.Empty; + } + } +} diff --git a/Tests/BasicTests/ContinuousSubstitute.cs b/Tests/BasicTests/ContinuousSubstitute.cs index 2ce65c89..80f77f9e 100644 --- a/Tests/BasicTests/ContinuousSubstitute.cs +++ b/Tests/BasicTests/ContinuousSubstitute.cs @@ -1,5 +1,4 @@ using DistTestCore; -using Logging; using NUnit.Framework; using Utils; @@ -9,21 +8,23 @@ namespace Tests.BasicTests public class ContinuousSubstitute : AutoBootstrapDistTest { [Test] - [UseLongTimeouts] public void ContinuousTestSubstitute() { var group = SetupCodexNodes(5, o => o .EnableMetrics() .EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: true) .WithBlockTTL(TimeSpan.FromMinutes(2)) - .WithStorageQuota(3.GB())); + .WithBlockMaintenanceInterval(TimeSpan.FromMinutes(2)) + .WithBlockMaintenanceNumber(10000) + .WithBlockTTL(TimeSpan.FromMinutes(2)) + .WithStorageQuota(1.GB())); var nodes = group.Cast().ToArray(); foreach (var node in nodes) { node.Marketplace.MakeStorageAvailable( - size: 1.GB(), + size: 500.MB(), minPricePerBytePerSecond: 1.TestTokens(), maxCollateral: 1024.TestTokens(), maxDuration: TimeSpan.FromMinutes(5)); @@ -43,6 +44,62 @@ namespace Tests.BasicTests } } + [Test] + public void PeerTest() + { + var group = SetupCodexNodes(5, o => o + .EnableMetrics() + .EnableMarketplace(100000.TestTokens(), 0.Eth(), isValidator: true) + .WithBlockTTL(TimeSpan.FromMinutes(2)) + .WithBlockMaintenanceInterval(TimeSpan.FromMinutes(2)) + .WithBlockMaintenanceNumber(10000) + .WithBlockTTL(TimeSpan.FromMinutes(2)) + .WithStorageQuota(1.GB())); + + var nodes = group.Cast().ToArray(); + + var checkTime = DateTime.UtcNow + TimeSpan.FromMinutes(1); + var endTime = DateTime.UtcNow + TimeSpan.FromHours(10); + while (DateTime.UtcNow < endTime) + { + CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes()); + + if (DateTime.UtcNow > checkTime) + { + CheckRoutingTables(GetAllOnlineCodexNodes()); + } + + Thread.Sleep(5000); + } + } + + private void CheckRoutingTables(IEnumerable nodes) + { + var all = nodes.ToArray(); + var allIds = all.Select(n => n.GetDebugInfo().table.localNode.nodeId).ToArray(); + + var errors = all.Select(n => AreAllPresent(n, allIds)).Where(s => !string.IsNullOrEmpty(s)).ToArray(); + + if (errors.Any()) + { + Assert.Fail(string.Join(Environment.NewLine, errors)); + } + } + + private string AreAllPresent(IOnlineCodexNode n, string[] allIds) + { + var info = n.GetDebugInfo(); + var known = info.table.nodes.Select(n => n.nodeId).ToArray(); + var expected = allIds.Where(i => i != info.table.localNode.nodeId).ToArray(); + + if (!expected.All(ex => known.Contains(ex))) + { + return $"Not all of '{string.Join(",", expected)}' were present in routing table: '{string.Join(",", known)}'"; + } + + return string.Empty; + } + private ByteSize fileSize = 80.MB(); private void PerformTest(IOnlineCodexNode primary, IOnlineCodexNode secondary)