From ec5aebb47b6b7ba114f849a8b5610e1d2e2d1c90 Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 13 Sep 2023 14:24:43 +0200 Subject: [PATCH] Restores full-connectivity tests. --- DistTestCore/DistTest.cs | 14 +---- DistTestCore/TestLifecycle.cs | 4 +- Tests/AutoBootstrapDistTest.cs | 41 ++++---------- Tests/CodexDistTest.cs | 56 +++++++++++++++++++ .../FullyConnectedDownloadTests.cs | 8 +-- Tests/Helpers/PeerDownloadTestHelpers.cs | 4 +- .../LayeredDiscoveryTests.cs | 5 +- .../PeerDiscoveryTests/PeerDiscoveryTests.cs | 5 +- 8 files changed, 80 insertions(+), 57 deletions(-) create mode 100644 Tests/CodexDistTest.cs diff --git a/DistTestCore/DistTest.cs b/DistTestCore/DistTest.cs index e5b202f..ac7063d 100644 --- a/DistTestCore/DistTest.cs +++ b/DistTestCore/DistTest.cs @@ -110,7 +110,7 @@ namespace DistTestCore /// public void ScopedTestFiles(Action action) { - Get().ScopedTestFiles(action); + Get().GetFileManager().ScopedFiles(action); } //public IOnlineCodexNode SetupCodexBootstrapNode() @@ -183,16 +183,6 @@ namespace DistTestCore GetTestLog().Debug(msg); } - //public PeerConnectionTestHelpers CreatePeerConnectionTestHelpers() - //{ - // return new PeerConnectionTestHelpers(GetTestLog()); - //} - - //public PeerDownloadTestHelpers CreatePeerDownloadTestHelpers() - //{ - // return new PeerDownloadTestHelpers(GetTestLog(), Get().FileManager); - //} - public void Measure(string name, Action action) { Stopwatch.Measure(Get().Log, name, action); @@ -203,7 +193,7 @@ namespace DistTestCore // return new CodexSetup(numberOfNodes, configuration.GetCodexLogLevel()); //} - private TestLifecycle Get() + protected TestLifecycle Get() { lock (lifecycleLock) { diff --git a/DistTestCore/TestLifecycle.cs b/DistTestCore/TestLifecycle.cs index 53b95e9..4af6bc5 100644 --- a/DistTestCore/TestLifecycle.cs +++ b/DistTestCore/TestLifecycle.cs @@ -40,9 +40,9 @@ namespace DistTestCore return entryPoint.Tools.GetFileManager().GenerateFile(size, label); } - public void ScopedTestFiles(Action action) + public IFileManager GetFileManager() { - entryPoint.Tools.GetFileManager().ScopedFiles(action); + return entryPoint.Tools.GetFileManager(); } //public IDownloadedLog DownloadLog(RunningContainer container, int? tailLines = null) diff --git a/Tests/AutoBootstrapDistTest.cs b/Tests/AutoBootstrapDistTest.cs index b22b439..fce68b8 100644 --- a/Tests/AutoBootstrapDistTest.cs +++ b/Tests/AutoBootstrapDistTest.cs @@ -1,45 +1,26 @@ using CodexPlugin; using DistTestCore; +using DistTestCore.Helpers; using NUnit.Framework; namespace Tests { - public class AutoBootstrapDistTest : DistTest + public class AutoBootstrapDistTest : CodexDistTest { - public IOnlineCodexNode AddCodex() - { - return AddCodex(s => { }); - } - - public IOnlineCodexNode AddCodex(Action setup) - { - return Ci.SetupCodexNode(s => - { - setup(s); - s.WithBootstrapNode(BootstrapNode); - }); - } - - public ICodexNodeGroup AddCodex(int numberOfNodes) - { - return Ci.SetupCodexNodes(numberOfNodes, s => s.WithBootstrapNode(BootstrapNode)); - } - - public ICodexNodeGroup AddCodex(int numberOfNodes, Action setup) - { - return Ci.SetupCodexNodes(numberOfNodes, s => - { - setup(s); - s.WithBootstrapNode(BootstrapNode); - }); - } + private readonly List onlineCodexNodes = new List(); [SetUp] public void SetUpBootstrapNode() { - BootstrapNode = Ci.SetupCodexNode(s => s.WithName("BOOTSTRAP")); + BootstrapNode = AddCodex(s => s.WithName("BOOTSTRAP")); + onlineCodexNodes.Add(BootstrapNode); } - protected IOnlineCodexNode BootstrapNode { get; private set; } = null!; + protected override void OnCodexSetup(ICodexSetup setup) + { + if (BootstrapNode != null) setup.WithBootstrapNode(BootstrapNode); + } + + protected IOnlineCodexNode? BootstrapNode { get; private set; } } } diff --git a/Tests/CodexDistTest.cs b/Tests/CodexDistTest.cs new file mode 100644 index 0000000..6ecd203 --- /dev/null +++ b/Tests/CodexDistTest.cs @@ -0,0 +1,56 @@ +using CodexPlugin; +using DistTestCore; +using DistTestCore.Helpers; + +namespace Tests +{ + public class CodexDistTest : DistTest + { + private readonly List onlineCodexNodes = new List(); + + public IOnlineCodexNode AddCodex() + { + return AddCodex(s => { }); + } + + public IOnlineCodexNode AddCodex(Action setup) + { + return AddCodex(1, setup)[0]; + } + + public ICodexNodeGroup AddCodex(int numberOfNodes) + { + return AddCodex(numberOfNodes, s => { }); + } + + public ICodexNodeGroup AddCodex(int numberOfNodes, Action setup) + { + var group = Ci.SetupCodexNodes(numberOfNodes, s => + { + setup(s); + OnCodexSetup(s); + }); + onlineCodexNodes.AddRange(group); + return group; + } + + public PeerConnectionTestHelpers CreatePeerConnectionTestHelpers() + { + return new PeerConnectionTestHelpers(GetTestLog()); + } + + public PeerDownloadTestHelpers CreatePeerDownloadTestHelpers() + { + return new PeerDownloadTestHelpers(GetTestLog(), Get().GetFileManager()); + } + + public IEnumerable GetAllOnlineCodexNodes() + { + return onlineCodexNodes; + } + + protected virtual void OnCodexSetup(ICodexSetup setup) + { + } + } +} diff --git a/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs b/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs index 4728389..ed66240 100644 --- a/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs +++ b/Tests/DownloadConnectivityTests/FullyConnectedDownloadTests.cs @@ -1,6 +1,4 @@ -using CodexPlugin; -using DistTestCore; -using NUnit.Framework; +using NUnit.Framework; using Utils; namespace Tests.DownloadConnectivityTests @@ -11,7 +9,7 @@ namespace Tests.DownloadConnectivityTests [Test] public void MetricsDoesNotInterfereWithPeerDownload() { - //AddCodex(2, s => s.EnableMetrics()); + AddCodex(2, s => s.EnableMetrics()); AssertAllNodesConnected(); } @@ -37,7 +35,7 @@ namespace Tests.DownloadConnectivityTests private void AssertAllNodesConnected(int sizeMBs = 10) { - //CreatePeerDownloadTestHelpers().AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB()); + CreatePeerDownloadTestHelpers().AssertFullDownloadInterconnectivity(GetAllOnlineCodexNodes(), sizeMBs.MB()); } } } diff --git a/Tests/Helpers/PeerDownloadTestHelpers.cs b/Tests/Helpers/PeerDownloadTestHelpers.cs index a3e75b3..3af375d 100644 --- a/Tests/Helpers/PeerDownloadTestHelpers.cs +++ b/Tests/Helpers/PeerDownloadTestHelpers.cs @@ -10,10 +10,10 @@ namespace DistTestCore.Helpers { private readonly FullConnectivityHelper helper; private readonly ILog log; - private readonly FileManager fileManager; + private readonly IFileManager fileManager; private ByteSize testFileSize; - public PeerDownloadTestHelpers(ILog log, FileManager fileManager) + public PeerDownloadTestHelpers(ILog log, IFileManager fileManager) { helper = new FullConnectivityHelper(log, this); testFileSize = 1.MB(); diff --git a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs index b5e7edf..088fbcb 100644 --- a/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/LayeredDiscoveryTests.cs @@ -1,11 +1,10 @@ using CodexPlugin; -using DistTestCore; using NUnit.Framework; namespace Tests.PeerDiscoveryTests { [TestFixture] - public class LayeredDiscoveryTests : DistTest + public class LayeredDiscoveryTests : CodexDistTest { [Test] public void TwoLayersTest() @@ -47,7 +46,7 @@ namespace Tests.PeerDiscoveryTests private void AssertAllNodesConnected() { - //CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes()); + CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes()); } } } diff --git a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs index 9a55cf4..4141925 100644 --- a/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs +++ b/Tests/PeerDiscoveryTests/PeerDiscoveryTests.cs @@ -1,5 +1,4 @@ -using DistTestCore; -using NUnit.Framework; +using NUnit.Framework; namespace Tests.PeerDiscoveryTests { @@ -45,7 +44,7 @@ namespace Tests.PeerDiscoveryTests private void AssertAllNodesConnected() { - //CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes()); + CreatePeerConnectionTestHelpers().AssertFullyConnected(GetAllOnlineCodexNodes()); } } }