From 62f4eed221a5cce5d3211324bd024c929472481e Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 25 Apr 2023 12:52:11 +0200 Subject: [PATCH] Removes BringOnline method --- DistTestCore/CodexSetup.cs | 11 +--------- DistTestCore/DistTest.cs | 28 ++++++++++++++++++++++-- DistTestCore/OnlineCodexNode.cs | 6 +++++ LongTests/BasicTests/LargeFileTests.cs | 5 ++--- LongTests/BasicTests/TestInfraTests.cs | 11 ++++------ Tests/BasicTests/ExampleTests.cs | 23 ++++++------------- Tests/BasicTests/OneClientTests.cs | 8 +++---- Tests/BasicTests/TwoClientTests.cs | 16 +++++--------- Tests/DurabilityTests/DurabilityTests.cs | 10 ++++----- 9 files changed, 60 insertions(+), 58 deletions(-) diff --git a/DistTestCore/CodexSetup.cs b/DistTestCore/CodexSetup.cs index 618cd06..4adaecf 100644 --- a/DistTestCore/CodexSetup.cs +++ b/DistTestCore/CodexSetup.cs @@ -13,26 +13,17 @@ namespace DistTestCore ICodexSetup EnableMetrics(); ICodexSetup EnableMarketplace(TestToken initialBalance); ICodexSetup EnableMarketplace(TestToken initialBalance, Ether initialEther); - ICodexNodeGroup BringOnline(); } public class CodexSetup : CodexStartupConfig, ICodexSetup { - private readonly CodexStarter starter; - public int NumberOfNodes { get; } - public CodexSetup(CodexStarter starter, int numberOfNodes) + public CodexSetup(int numberOfNodes) { - this.starter = starter; NumberOfNodes = numberOfNodes; } - public ICodexNodeGroup BringOnline() - { - return starter.BringOnline(this); - } - public ICodexSetup At(Location location) { Location = location; diff --git a/DistTestCore/DistTest.cs b/DistTestCore/DistTest.cs index b24bb5b..9e79e13 100644 --- a/DistTestCore/DistTest.cs +++ b/DistTestCore/DistTest.cs @@ -77,9 +77,33 @@ namespace DistTestCore return lifecycle.FileManager.GenerateTestFile(size); } - public ICodexSetup SetupCodexNodes(int numberOfNodes) + public IOnlineCodexNode SetupCodexNode() { - return new CodexSetup(lifecycle.CodexStarter, numberOfNodes); + return SetupCodexNode(s => { }); + } + + public IOnlineCodexNode SetupCodexNode(Action setup) + { + return SetupCodexNodes(1, setup)[0]; + } + + public ICodexNodeGroup SetupCodexNodes(int numberOfNodes) + { + return SetupCodexNodes(numberOfNodes, s => { }); + } + + public ICodexNodeGroup SetupCodexNodes(int numberOfNodes, Action setup) + { + var codexSetup = new CodexSetup(numberOfNodes); + + setup(codexSetup); + + return BringOnline(codexSetup); + } + + public ICodexNodeGroup BringOnline(ICodexSetup codexSetup) + { + return lifecycle.CodexStarter.BringOnline((CodexSetup)codexSetup); } private void CreateNewTestLifecycle() diff --git a/DistTestCore/OnlineCodexNode.cs b/DistTestCore/OnlineCodexNode.cs index 149bc0e..6950591 100644 --- a/DistTestCore/OnlineCodexNode.cs +++ b/DistTestCore/OnlineCodexNode.cs @@ -16,6 +16,7 @@ namespace DistTestCore ICodexNodeLog DownloadLog(); IMetricsAccess Metrics { get; } IMarketplaceAccess Marketplace { get; } + ICodexSetup BringOffline(); } public class OnlineCodexNode : IOnlineCodexNode @@ -89,6 +90,11 @@ namespace DistTestCore return lifecycle.DownloadLog(this); } + public ICodexSetup BringOffline() + { + return Group.BringOffline(); + } + private string GetPeerMultiAddress(OnlineCodexNode peer, CodexDebugResponse peerInfo) { var multiAddress = peerInfo.addrs.First(); diff --git a/LongTests/BasicTests/LargeFileTests.cs b/LongTests/BasicTests/LargeFileTests.cs index 3db5d59..63b33f5 100644 --- a/LongTests/BasicTests/LargeFileTests.cs +++ b/LongTests/BasicTests/LargeFileTests.cs @@ -10,10 +10,9 @@ namespace TestsLong.BasicTests [Test, UseLongTimeouts] public void OneClientLargeFileTest() { - var primary = SetupCodexNodes(1) + var primary = SetupCodexNode(s => s .WithLogLevel(CodexLogLevel.Warn) - .WithStorageQuota(20.GB()) - .BringOnline()[0]; + .WithStorageQuota(20.GB())); var testFile = GenerateTestFile(10.GB()); diff --git a/LongTests/BasicTests/TestInfraTests.cs b/LongTests/BasicTests/TestInfraTests.cs index 7acd78e..0b5e640 100644 --- a/LongTests/BasicTests/TestInfraTests.cs +++ b/LongTests/BasicTests/TestInfraTests.cs @@ -9,9 +9,7 @@ namespace TestsLong.BasicTests [Test, UseLongTimeouts] public void TestInfraShouldHave1000AddressSpacesPerPod() { - var group = SetupCodexNodes(1000) - .EnableMetrics() // Increases use of port address space per node. - .BringOnline(); + var group = SetupCodexNodes(1000, s => s.EnableMetrics()); // Increases use of port address space per node. var nodeIds = group.Select(n => n.GetDebugInfo().id).ToArray(); @@ -24,7 +22,7 @@ namespace TestsLong.BasicTests { for (var i = 0; i < 20; i++) { - var n = SetupCodexNodes(1).BringOnline()[0]; + var n = SetupCodexNode(); Assert.That(!string.IsNullOrEmpty(n.GetDebugInfo().id)); } @@ -33,10 +31,9 @@ namespace TestsLong.BasicTests [Test, UseLongTimeouts] public void DownloadConsistencyTest() { - var primary = SetupCodexNodes(1) + var primary = SetupCodexNode(s => s .WithLogLevel(CodexLogLevel.Trace) - .WithStorageQuota(2.MB()) - .BringOnline()[0]; + .WithStorageQuota(2.MB())); var testFile = GenerateTestFile(1.MB()); diff --git a/Tests/BasicTests/ExampleTests.cs b/Tests/BasicTests/ExampleTests.cs index e1beb7d..e06dee8 100644 --- a/Tests/BasicTests/ExampleTests.cs +++ b/Tests/BasicTests/ExampleTests.cs @@ -11,9 +11,7 @@ namespace Tests.BasicTests [Test] public void CodexLogExample() { - var primary = SetupCodexNodes(1) - .WithLogLevel(CodexLogLevel.Trace) - .BringOnline()[0]; + var primary = SetupCodexNode(s => s.WithLogLevel(CodexLogLevel.Trace)); primary.UploadFile(GenerateTestFile(5.MB())); @@ -25,13 +23,8 @@ namespace Tests.BasicTests [Test] public void TwoMetricsExample() { - var group = SetupCodexNodes(2) - .EnableMetrics() - .BringOnline(); - - var group2 = SetupCodexNodes(2) - .EnableMetrics() - .BringOnline(); + var group = SetupCodexNodes(2, s => s.EnableMetrics()); + var group2 = SetupCodexNodes(2, s => s.EnableMetrics()); var primary = group[0]; var secondary = group[1]; @@ -50,19 +43,17 @@ namespace Tests.BasicTests [Test] public void MarketplaceExample() { - var primary = SetupCodexNodes(1) + var primary = SetupCodexNode(s => s .WithLogLevel(CodexLogLevel.Trace) .WithStorageQuota(11.GB()) - .EnableMarketplace(initialBalance: 234.TestTokens()) - .BringOnline()[0]; + .EnableMarketplace(initialBalance: 234.TestTokens())); primary.Marketplace.AssertThatBalance(Is.EqualTo(234.TestTokens())); - var secondary = SetupCodexNodes(1) + var secondary = SetupCodexNode(s => s .WithLogLevel(CodexLogLevel.Trace) .WithBootstrapNode(primary) - .EnableMarketplace(initialBalance: 1000.TestTokens()) - .BringOnline()[0]; + .EnableMarketplace(initialBalance: 1000.TestTokens())); primary.Marketplace.MakeStorageAvailable( size: 10.GB(), diff --git a/Tests/BasicTests/OneClientTests.cs b/Tests/BasicTests/OneClientTests.cs index a2c0c57..b22e53b 100644 --- a/Tests/BasicTests/OneClientTests.cs +++ b/Tests/BasicTests/OneClientTests.cs @@ -9,7 +9,7 @@ namespace Tests.BasicTests [Test] public void OneClientTest() { - var primary = SetupCodexNodes(1).BringOnline()[0]; + var primary = SetupCodexNode(); PerformOneClientTest(primary); } @@ -17,11 +17,11 @@ namespace Tests.BasicTests [Test] public void RestartTest() { - var group = SetupCodexNodes(1).BringOnline(); + var primary = SetupCodexNode(); - var setup = group.BringOffline(); + var setup = primary.BringOffline(); - var primary = setup.BringOnline()[0]; + primary = BringOnline(setup)[0]; PerformOneClientTest(primary); } diff --git a/Tests/BasicTests/TwoClientTests.cs b/Tests/BasicTests/TwoClientTests.cs index cde3b04..90af450 100644 --- a/Tests/BasicTests/TwoClientTests.cs +++ b/Tests/BasicTests/TwoClientTests.cs @@ -10,7 +10,7 @@ namespace Tests.BasicTests [Test] public void TwoClientsOnePodTest() { - var group = SetupCodexNodes(2).BringOnline(); + var group = SetupCodexNodes(2); var primary = group[0]; var secondary = group[1]; @@ -21,9 +21,8 @@ namespace Tests.BasicTests [Test] public void TwoClientsTwoPodsTest() { - var primary = SetupCodexNodes(1).BringOnline()[0]; - - var secondary = SetupCodexNodes(1).BringOnline()[0]; + var primary = SetupCodexNode(); + var secondary = SetupCodexNode(); PerformTwoClientTest(primary, secondary); } @@ -32,13 +31,8 @@ namespace Tests.BasicTests [Ignore("Requires Location map to be configured for k8s cluster.")] public void TwoClientsTwoLocationsTest() { - var primary = SetupCodexNodes(1) - .At(Location.BensLaptop) - .BringOnline()[0]; - - var secondary = SetupCodexNodes(1) - .At(Location.BensOldGamingMachine) - .BringOnline()[0]; + var primary = SetupCodexNode(s => s.At(Location.BensLaptop)); + var secondary = SetupCodexNode(s => s.At(Location.BensOldGamingMachine)); PerformTwoClientTest(primary, secondary); } diff --git a/Tests/DurabilityTests/DurabilityTests.cs b/Tests/DurabilityTests/DurabilityTests.cs index 53d6ab3..584d1c6 100644 --- a/Tests/DurabilityTests/DurabilityTests.cs +++ b/Tests/DurabilityTests/DurabilityTests.cs @@ -11,8 +11,8 @@ namespace Tests.DurabilityTests [Test] public void BootstrapNodeDisappearsTest() { - var bootstrapNode = SetupCodexNodes(1).BringOnline(); - var group = SetupCodexNodes(2).WithBootstrapNode(bootstrapNode[0]).BringOnline(); + var bootstrapNode = SetupCodexNode(); + var group = SetupCodexNodes(2, s => s.WithBootstrapNode(bootstrapNode)); var primary = group[0]; var secondary = group[1]; @@ -31,10 +31,10 @@ namespace Tests.DurabilityTests [Test] public void DataRetentionTest() { - var bootstrapNode = SetupCodexNodes(1).WithLogLevel(CodexLogLevel.Trace).BringOnline()[0]; + var bootstrapNode = SetupCodexNode(s => s.WithLogLevel(CodexLogLevel.Trace)); - var startGroup = SetupCodexNodes(2).WithLogLevel(CodexLogLevel.Trace).WithBootstrapNode(bootstrapNode).BringOnline(); - var finishGroup = SetupCodexNodes(10).WithLogLevel(CodexLogLevel.Trace).WithBootstrapNode(bootstrapNode).BringOnline(); + var startGroup = SetupCodexNodes(2, s => s.WithLogLevel(CodexLogLevel.Trace).WithBootstrapNode(bootstrapNode)); + var finishGroup = SetupCodexNodes(10, s => s.WithLogLevel(CodexLogLevel.Trace).WithBootstrapNode(bootstrapNode)); var file = GenerateTestFile(10.MB());