From e33a6776e58dacc2402605f2593efd59c0646747 Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 6 Jun 2023 14:36:37 +0200 Subject: [PATCH] Cleanup --- .../Helpers/PeerConnectionTestHelpers.cs | 12 +++++-- .../Helpers/PeerDownloadTestHelpers.cs | 20 +++++++++++- DistTestCore/OnlineCodexNode.cs | 4 ++- .../LayeredDiscoveryTests.cs | 8 ----- .../PeerDiscoveryTests/PeerDiscoveryTests.cs | 32 ------------------- 5 files changed, 32 insertions(+), 44 deletions(-) diff --git a/DistTestCore/Helpers/PeerConnectionTestHelpers.cs b/DistTestCore/Helpers/PeerConnectionTestHelpers.cs index 54f3c43..5eb0cdf 100644 --- a/DistTestCore/Helpers/PeerConnectionTestHelpers.cs +++ b/DistTestCore/Helpers/PeerConnectionTestHelpers.cs @@ -16,10 +16,18 @@ namespace DistTestCore.Helpers public void AssertFullyConnected(IEnumerable nodes) { - AssertFullyConnected(nodes.ToArray()); + var n = nodes.ToArray(); + + AssertFullyConnected(n); + + for (int i = 0; i < 5; i++) + { + Time.Sleep(TimeSpan.FromSeconds(30)); + AssertFullyConnected(n); + } } - public void AssertFullyConnected(params IOnlineCodexNode[] nodes) + private void AssertFullyConnected(IOnlineCodexNode[] nodes) { test.Log($"Asserting peers are fully-connected for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'..."); var entries = CreateEntries(nodes); diff --git a/DistTestCore/Helpers/PeerDownloadTestHelpers.cs b/DistTestCore/Helpers/PeerDownloadTestHelpers.cs index c218ac0..1e8812c 100644 --- a/DistTestCore/Helpers/PeerDownloadTestHelpers.cs +++ b/DistTestCore/Helpers/PeerDownloadTestHelpers.cs @@ -1,4 +1,7 @@ -namespace DistTestCore.Helpers +using Nethereum.Model; +using NUnit.Framework; + +namespace DistTestCore.Helpers { public class PeerDownloadTestHelpers { @@ -17,6 +20,8 @@ public void AssertFullDownloadInterconnectivity(IEnumerable nodes, ByteSize testFileSize) { test.Log($"Asserting full download interconnectivity for nodes: '{string.Join(",", nodes.Select(n => n.GetName()))}'..."); + var start = DateTime.UtcNow; + foreach (var node in nodes) { var uploader = node; @@ -29,6 +34,19 @@ } test.Log($"Success! Full download interconnectivity for nodes: {string.Join(",", nodes.Select(n => n.GetName()))}"); + var timeTaken = DateTime.UtcNow - start; + + AssertTimePerDownload(timeTaken, nodes.Count()); + } + + private void AssertTimePerDownload(TimeSpan timeTaken, int numberOfNodes) + { + var numberOfDownloads = numberOfNodes * (numberOfNodes - 1); + var timePerDownload = timeTaken / numberOfDownloads; + + test.Log($"Performed {numberOfDownloads} downloads in {timeTaken.TotalSeconds} seconds, for an average of {timePerDownload.TotalSeconds} seconds per download."); + + Assert.That(timePerDownload.TotalSeconds, Is.LessThan(20.0f), "Seconds-per-Download breached performance threshold."); } private void PerformTest(IOnlineCodexNode uploader, IOnlineCodexNode[] downloaders, ByteSize testFileSize) diff --git a/DistTestCore/OnlineCodexNode.cs b/DistTestCore/OnlineCodexNode.cs index a1197f6..270ebc1 100644 --- a/DistTestCore/OnlineCodexNode.cs +++ b/DistTestCore/OnlineCodexNode.cs @@ -73,7 +73,9 @@ namespace DistTestCore { Assert.Fail("Node failed to store block."); } - lifecycle.Log.AddStringReplace(response, $"(CID:{file.Describe()})"); + var logReplacement = $"(CID:{file.Describe()})"; + Log($"ContentId '{response}' is {logReplacement}"); + lifecycle.Log.AddStringReplace(response, logReplacement); Log($"Uploaded file. Received contentId: '{response}'."); return new ContentId(response); } diff --git a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs index ad04144..aeb414a 100644 --- a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs @@ -1,7 +1,6 @@ using DistTestCore; using DistTestCore.Helpers; using NUnit.Framework; -using Utils; namespace Tests.PeerDiscoveryTests { @@ -35,7 +34,6 @@ namespace Tests.PeerDiscoveryTests [TestCase(5)] [TestCase(10)] [TestCase(20)] - [TestCase(50)] public void NodeChainTest(int chainLength) { var node = SetupCodexNode(); @@ -45,12 +43,6 @@ namespace Tests.PeerDiscoveryTests } AssertAllNodesConnected(); - - for (int i = 0; i < 5; i++) - { - Time.Sleep(TimeSpan.FromSeconds(30)); - AssertAllNodesConnected(); - } } private void AssertAllNodesConnected() diff --git a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs index 841b072..57b79cf 100644 --- a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs @@ -18,16 +18,6 @@ namespace Tests.PeerDiscoveryTests Assert.That(result.IsPeerFound, Is.False); } - [TestCase(2)] - [TestCase(3)] - [TestCase(10)] - public void VariableNodes(int number) - { - SetupCodexNodes(number); - - AssertAllNodesConnected(); - } - [TestCase(2)] [TestCase(3)] [TestCase(10)] @@ -42,28 +32,6 @@ namespace Tests.PeerDiscoveryTests AssertAllNodesConnected(); } - [TestCase(3, 3)] - [TestCase(3, 5)] - [TestCase(3, 10)] - [TestCase(5, 10)] - [TestCase(3, 20)] - [TestCase(5, 20)] - public void StagedVariableNodes(int numberOfNodes, int numberOfStages) - { - for (var i = 0; i < numberOfStages; i++) - { - SetupCodexNodes(numberOfNodes); - - AssertAllNodesConnected(); - } - - for (int i = 0; i < 5; i++) - { - Time.Sleep(TimeSpan.FromSeconds(30)); - AssertAllNodesConnected(); - } - } - private void AssertAllNodesConnected() { PeerConnectionTestHelpers.AssertFullyConnected(GetAllOnlineCodexNodes());