From b81d574a4b6d43c518645fac313ee17a75c17131 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 9 Oct 2023 16:59:52 +0200 Subject: [PATCH] adds block exchange tests. Updates namespaces --- .../Tests/TwoClientTest.cs | 13 ++++ .../BasicTests/DownloadTests.cs | 2 +- .../BasicTests/LargeFileTests.cs | 2 +- .../BasicTests/TestInfraTests.cs | 4 +- .../CodexLongTests/BasicTests/UploadTests.cs | 2 +- .../LongFullyConnectedDownloadTests.cs | 4 +- Tests/CodexTests/AutoBootstrapDistTest.cs | 2 +- .../BasicTests/BlockExchangeTests.cs | 62 +++++++++++++++++++ .../BasicTests/ContinuousSubstitute.cs | 4 +- Tests/CodexTests/BasicTests/ExampleTests.cs | 6 +- .../BasicTests/NetworkIsolationTest.cs | 2 +- Tests/CodexTests/BasicTests/OneClientTests.cs | 2 +- .../CodexTests/BasicTests/ThreeClientTest.cs | 5 +- Tests/CodexTests/BasicTests/TwoClientTests.cs | 2 +- Tests/CodexTests/CodexDistTest.cs | 2 +- .../FullyConnectedDownloadTests.cs | 1 + Tests/CodexTests/MetricsAccessExtensions.cs | 2 +- Tests/CodexTests/Parallelism.cs | 2 +- .../LayeredDiscoveryTests.cs | 1 + .../PeerDiscoveryTests/PeerDiscoveryTests.cs | 1 + 20 files changed, 99 insertions(+), 22 deletions(-) create mode 100644 Tests/CodexTests/BasicTests/BlockExchangeTests.cs diff --git a/Tests/CodexContinuousTests/Tests/TwoClientTest.cs b/Tests/CodexContinuousTests/Tests/TwoClientTest.cs index 6a382be..0035d01 100644 --- a/Tests/CodexContinuousTests/Tests/TwoClientTest.cs +++ b/Tests/CodexContinuousTests/Tests/TwoClientTest.cs @@ -1,6 +1,7 @@ using CodexPlugin; using FileUtils; using Logging; +using Newtonsoft.Json; using NUnit.Framework; using Utils; @@ -21,6 +22,9 @@ namespace ContinuousTests.Tests [TestMoment(t: Zero)] public void UploadTestFile() { + LogBlockExchangeStatus(Nodes[0], "Before upload"); + LogBlockExchangeStatus(Nodes[1], "Before upload"); + file = FileManager.GenerateFile(size); LogStoredBytes(Nodes[0]); @@ -37,6 +41,9 @@ namespace ContinuousTests.Tests LogBytesPerMillisecond(() => dl = Nodes[1].DownloadContent(cid!)); file.AssertIsEqual(dl); + + LogBlockExchangeStatus(Nodes[0], "After download"); + LogBlockExchangeStatus(Nodes[1], "After download"); } private void LogStoredBytes(ICodexNode node) @@ -65,5 +72,11 @@ namespace ContinuousTests.Tests var bytesPerMs = totalBytes / totalMs; Log.Log($"Bytes per millisecond: {bytesPerMs}"); } + + private void LogBlockExchangeStatus(ICodexNode codexNode, string msg) + { + var response = codexNode.GetDebugBlockExchange(); + Log.Log($"{codexNode.GetName()} {msg}: {JsonConvert.SerializeObject(response)}"); + } } } diff --git a/Tests/CodexLongTests/BasicTests/DownloadTests.cs b/Tests/CodexLongTests/BasicTests/DownloadTests.cs index 68de3b1..533934d 100644 --- a/Tests/CodexLongTests/BasicTests/DownloadTests.cs +++ b/Tests/CodexLongTests/BasicTests/DownloadTests.cs @@ -1,7 +1,7 @@ +using CodexTests; using DistTestCore; using FileUtils; using NUnit.Framework; -using Tests; using Utils; namespace CodexLongTests.BasicTests diff --git a/Tests/CodexLongTests/BasicTests/LargeFileTests.cs b/Tests/CodexLongTests/BasicTests/LargeFileTests.cs index 68eb1a7..1a6e21c 100644 --- a/Tests/CodexLongTests/BasicTests/LargeFileTests.cs +++ b/Tests/CodexLongTests/BasicTests/LargeFileTests.cs @@ -1,8 +1,8 @@ using CodexPlugin; +using CodexTests; using DistTestCore; using NUnit.Framework; using NUnit.Framework.Interfaces; -using Tests; using Utils; namespace CodexLongTests.BasicTests diff --git a/Tests/CodexLongTests/BasicTests/TestInfraTests.cs b/Tests/CodexLongTests/BasicTests/TestInfraTests.cs index caad570..832f13a 100644 --- a/Tests/CodexLongTests/BasicTests/TestInfraTests.cs +++ b/Tests/CodexLongTests/BasicTests/TestInfraTests.cs @@ -1,6 +1,6 @@ -using DistTestCore; +using CodexTests; +using DistTestCore; using NUnit.Framework; -using Tests; namespace CodexLongTests.BasicTests { diff --git a/Tests/CodexLongTests/BasicTests/UploadTests.cs b/Tests/CodexLongTests/BasicTests/UploadTests.cs index b2cadc0..57e0296 100644 --- a/Tests/CodexLongTests/BasicTests/UploadTests.cs +++ b/Tests/CodexLongTests/BasicTests/UploadTests.cs @@ -1,8 +1,8 @@ using CodexPlugin; +using CodexTests; using DistTestCore; using FileUtils; using NUnit.Framework; -using Tests; using Utils; namespace CodexLongTests.BasicTests diff --git a/Tests/CodexLongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs b/Tests/CodexLongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs index 5858d53..8f57e38 100644 --- a/Tests/CodexLongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs +++ b/Tests/CodexLongTests/DownloadConnectivityTests/LongFullyConnectedDownloadTests.cs @@ -1,6 +1,6 @@ -using DistTestCore; +using CodexTests; +using DistTestCore; using NUnit.Framework; -using Tests; using Utils; namespace CodexLongTests.DownloadConnectivityTests diff --git a/Tests/CodexTests/AutoBootstrapDistTest.cs b/Tests/CodexTests/AutoBootstrapDistTest.cs index 869453a..694b255 100644 --- a/Tests/CodexTests/AutoBootstrapDistTest.cs +++ b/Tests/CodexTests/AutoBootstrapDistTest.cs @@ -1,7 +1,7 @@ using CodexPlugin; using NUnit.Framework; -namespace Tests +namespace CodexTests { public class AutoBootstrapDistTest : CodexDistTest { diff --git a/Tests/CodexTests/BasicTests/BlockExchangeTests.cs b/Tests/CodexTests/BasicTests/BlockExchangeTests.cs new file mode 100644 index 0000000..72d7357 --- /dev/null +++ b/Tests/CodexTests/BasicTests/BlockExchangeTests.cs @@ -0,0 +1,62 @@ +using CodexPlugin; +using NUnit.Framework; +using Utils; + +namespace CodexTests.BasicTests +{ + [TestFixture] + public class BlockExchangeTests : CodexDistTest + { + [Test] + public void EmptyAfterExchange() + { + var bootstrap = AddCodex(s => s.WithName("bootstrap")); + var node = AddCodex(s => s.WithName("node").WithBootstrapNode(bootstrap)); + + AssertExchangeIsEmpty(bootstrap, node); + + var file = GenerateTestFile(1.MB()); + var cid = bootstrap.UploadFile(file); + node.DownloadContent(cid); + + AssertExchangeIsEmpty(bootstrap, node); + } + + [Test] + public void EmptyAfterExchangeWithBystander() + { + var bootstrap = AddCodex(s => s.WithName("bootstrap")); + var node = AddCodex(s => s.WithName("node").WithBootstrapNode(bootstrap)); + var bystander = AddCodex(s => s.WithName("bystander").WithBootstrapNode(bootstrap)); + + AssertExchangeIsEmpty(bootstrap, node, bystander); + + var file = GenerateTestFile(1.MB()); + var cid = bootstrap.UploadFile(file); + node.DownloadContent(cid); + + AssertExchangeIsEmpty(bootstrap, node, bystander); + } + + private void AssertExchangeIsEmpty(params ICodexNode[] nodes) + { + foreach (var node in nodes) + { + Time.Retry(() => AssertBlockExchangeIsEmpty(node), nameof(AssertExchangeIsEmpty)); + } + } + + private void AssertBlockExchangeIsEmpty(ICodexNode node) + { + var msg = $"BlockExchange for {node.GetName()}: "; + var response = node.GetDebugBlockExchange(); + foreach (var peer in response.peers) + { + var activeWants = peer.wants.Where(w => !w.cancel).ToArray(); + Assert.That(activeWants.Length, Is.EqualTo(0), msg + "thinks a peer has active wants."); + } + Assert.That(response.taskQueue, Is.EqualTo(0), msg + "has tasks in queue."); + Assert.That(response.pendingBlocks, Is.EqualTo(0), msg + "has pending blocks."); + } + } +} diff --git a/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs b/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs index a5d3aea..fcb6880 100644 --- a/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs +++ b/Tests/CodexTests/BasicTests/ContinuousSubstitute.cs @@ -7,7 +7,7 @@ using MetricsPlugin; using NUnit.Framework; using Utils; -namespace Tests.BasicTests +namespace CodexTests.BasicTests { [Ignore("Used for debugging continuous tests")] [TestFixture] @@ -87,7 +87,7 @@ namespace Tests.BasicTests //CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes()); //CheckRoutingTables(GetAllOnlineCodexNodes()); - var node = RandomUtils.PickOneRandom(nodes.ToList()); + var node = nodes.ToList().PickOneRandom(); var file = GenerateTestFile(50.MB()); node.UploadFile(file); diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index 0db9bbb..cdd31bc 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -6,7 +6,7 @@ using MetricsPlugin; using NUnit.Framework; using Utils; -namespace Tests.BasicTests +namespace CodexTests.BasicTests { [TestFixture] public class ExampleTests : CodexDistTest @@ -59,7 +59,7 @@ namespace Tests.BasicTests .WithStorageQuota(11.GB()) .EnableMarketplace(geth, contracts, initialEth: 10.Eth(), initialTokens: sellerInitialBalance, isValidator: true) .WithSimulateProofFailures(failEveryNProofs: 3)); - + AssertBalance(geth, contracts, seller, Is.EqualTo(sellerInitialBalance)); seller.Marketplace.MakeStorageAvailable( size: 10.GB(), @@ -72,7 +72,7 @@ namespace Tests.BasicTests var buyer = AddCodex(s => s .WithBootstrapNode(seller) .EnableMarketplace(geth, contracts, initialEth: 10.Eth(), initialTokens: buyerInitialBalance)); - + AssertBalance(geth, contracts, buyer, Is.EqualTo(buyerInitialBalance)); var contentId = buyer.UploadFile(testFile); diff --git a/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs b/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs index 7388e4a..ccacdba 100644 --- a/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs +++ b/Tests/CodexTests/BasicTests/NetworkIsolationTest.cs @@ -3,7 +3,7 @@ using DistTestCore; using NUnit.Framework; using Utils; -namespace Tests.BasicTests +namespace CodexTests.BasicTests { // Warning! // This is a test to check network-isolation in the test-infrastructure. diff --git a/Tests/CodexTests/BasicTests/OneClientTests.cs b/Tests/CodexTests/BasicTests/OneClientTests.cs index 22fe0dd..de9c24e 100644 --- a/Tests/CodexTests/BasicTests/OneClientTests.cs +++ b/Tests/CodexTests/BasicTests/OneClientTests.cs @@ -3,7 +3,7 @@ using DistTestCore; using NUnit.Framework; using Utils; -namespace Tests.BasicTests +namespace CodexTests.BasicTests { [TestFixture] public class OneClientTests : DistTest diff --git a/Tests/CodexTests/BasicTests/ThreeClientTest.cs b/Tests/CodexTests/BasicTests/ThreeClientTest.cs index 5e44c97..bd9cdfb 100644 --- a/Tests/CodexTests/BasicTests/ThreeClientTest.cs +++ b/Tests/CodexTests/BasicTests/ThreeClientTest.cs @@ -1,8 +1,7 @@ -using DistTestCore; -using NUnit.Framework; +using NUnit.Framework; using Utils; -namespace Tests.BasicTests +namespace CodexTests.BasicTests { [TestFixture] public class ThreeClientTest : AutoBootstrapDistTest diff --git a/Tests/CodexTests/BasicTests/TwoClientTests.cs b/Tests/CodexTests/BasicTests/TwoClientTests.cs index a80e8e2..c781582 100644 --- a/Tests/CodexTests/BasicTests/TwoClientTests.cs +++ b/Tests/CodexTests/BasicTests/TwoClientTests.cs @@ -3,7 +3,7 @@ using DistTestCore; using NUnit.Framework; using Utils; -namespace Tests.BasicTests +namespace CodexTests.BasicTests { [TestFixture] public class TwoClientTests : DistTest diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index d521ad4..d29a1ea 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -9,7 +9,7 @@ using GethPlugin; using NUnit.Framework; using NUnit.Framework.Constraints; -namespace Tests +namespace CodexTests { public class CodexDistTest : DistTest { diff --git a/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs b/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs index 567c611..2f0a445 100644 --- a/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs +++ b/Tests/CodexTests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs @@ -1,4 +1,5 @@ using CodexContractsPlugin; +using CodexTests; using GethPlugin; using NUnit.Framework; using Utils; diff --git a/Tests/CodexTests/MetricsAccessExtensions.cs b/Tests/CodexTests/MetricsAccessExtensions.cs index aa5da83..0e26d93 100644 --- a/Tests/CodexTests/MetricsAccessExtensions.cs +++ b/Tests/CodexTests/MetricsAccessExtensions.cs @@ -3,7 +3,7 @@ using Logging; using MetricsPlugin; using NUnit.Framework.Constraints; -namespace Tests +namespace CodexTests { public static class MetricsAccessExtensions { diff --git a/Tests/CodexTests/Parallelism.cs b/Tests/CodexTests/Parallelism.cs index f45d8f2..a628e96 100644 --- a/Tests/CodexTests/Parallelism.cs +++ b/Tests/CodexTests/Parallelism.cs @@ -1,6 +1,6 @@ using NUnit.Framework; [assembly: LevelOfParallelism(1)] -namespace Tests +namespace CodexTests { } diff --git a/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs b/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs index 97675af..310b6aa 100644 --- a/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs +++ b/Tests/CodexTests/PeerDiscoveryTests/LayeredDiscoveryTests.cs @@ -1,4 +1,5 @@ using CodexPlugin; +using CodexTests; using NUnit.Framework; namespace Tests.PeerDiscoveryTests diff --git a/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs b/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs index 9327e7b..9eca0c6 100644 --- a/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs +++ b/Tests/CodexTests/PeerDiscoveryTests/PeerDiscoveryTests.cs @@ -1,4 +1,5 @@ using CodexContractsPlugin; +using CodexTests; using GethPlugin; using NUnit.Framework;