From 11269d1c211240af78bbaa887e2662fd9844ba9d Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 28 Jun 2023 12:01:20 +0200 Subject: [PATCH] Sets up transient node test --- ContinuousTests/ContinuousTest.cs | 3 +- ContinuousTests/ContinuousTestRunner.cs | 2 +- ContinuousTests/NodeRunner.cs | 16 +++++--- ContinuousTests/Tests/TransientNodeTest.cs | 47 ++++++++++++++++++++++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 ContinuousTests/Tests/TransientNodeTest.cs diff --git a/ContinuousTests/ContinuousTest.cs b/ContinuousTests/ContinuousTest.cs index cdbf6a8..4ac0da1 100644 --- a/ContinuousTests/ContinuousTest.cs +++ b/ContinuousTests/ContinuousTest.cs @@ -1,7 +1,6 @@ using DistTestCore; using DistTestCore.Codex; using Logging; -using Utils; namespace ContinuousTests { @@ -31,7 +30,7 @@ namespace ContinuousTests if (nodes != null) { - NodeRunner = new NodeRunner(Nodes.ToList().PickOneRandom(), configuration, TimeSet, Log, CustomK8sNamespace, EthereumAccountIndex); + NodeRunner = new NodeRunner(Nodes, configuration, TimeSet, Log, CustomK8sNamespace, EthereumAccountIndex); } else { diff --git a/ContinuousTests/ContinuousTestRunner.cs b/ContinuousTests/ContinuousTestRunner.cs index 8d7fe44..d9cd276 100644 --- a/ContinuousTests/ContinuousTestRunner.cs +++ b/ContinuousTests/ContinuousTestRunner.cs @@ -28,7 +28,7 @@ namespace ContinuousTests { overviewLog.Log("Launching test-loop for " + t.Name); t.Begin(); - Thread.Sleep(TimeSpan.FromMinutes(5)); + Thread.Sleep(TimeSpan.FromSeconds(15)); } overviewLog.Log("All test-loops launched."); diff --git a/ContinuousTests/NodeRunner.cs b/ContinuousTests/NodeRunner.cs index 5663817..92f17dc 100644 --- a/ContinuousTests/NodeRunner.cs +++ b/ContinuousTests/NodeRunner.cs @@ -4,21 +4,22 @@ using DistTestCore; using KubernetesWorkflow; using NUnit.Framework; using Logging; +using Utils; namespace ContinuousTests { public class NodeRunner { - private readonly CodexNode bootstrapNode; + private readonly CodexNode[] nodes; private readonly Configuration config; private readonly ITimeSet timeSet; private readonly BaseLog log; private readonly string customNamespace; private readonly int ethereumAccountIndex; - public NodeRunner(CodexNode bootstrapNode, Configuration config, ITimeSet timeSet, BaseLog log, string customNamespace, int ethereumAccountIndex) + public NodeRunner(CodexNode[] nodes, Configuration config, ITimeSet timeSet, BaseLog log, string customNamespace, int ethereumAccountIndex) { - this.bootstrapNode = bootstrapNode; + this.nodes = nodes; this.config = config; this.timeSet = timeSet; this.log = log; @@ -28,10 +29,15 @@ namespace ContinuousTests public void RunNode(Action operation) { - RunNode(operation, 0.TestTokens()); + RunNode(nodes.ToList().PickOneRandom(), operation, 0.TestTokens()); } - public void RunNode(Action operation, TestToken mintTestTokens) + public void RunNode(CodexNode bootstrapNode, Action operation) + { + RunNode(bootstrapNode, operation, 0.TestTokens()); + } + + public void RunNode(CodexNode bootstrapNode, Action operation, TestToken mintTestTokens) { var (workflowCreator, lifecycle) = CreateFacilities(); var flow = workflowCreator.CreateWorkflow(); diff --git a/ContinuousTests/Tests/TransientNodeTest.cs b/ContinuousTests/Tests/TransientNodeTest.cs new file mode 100644 index 0000000..24971e2 --- /dev/null +++ b/ContinuousTests/Tests/TransientNodeTest.cs @@ -0,0 +1,47 @@ +using DistTestCore; +using DistTestCore.Codex; +using NUnit.Framework; + +namespace ContinuousTests.Tests +{ + public class TransientNodeTest : ContinuousTest + { + public override int RequiredNumberOfNodes => 3; + public override TimeSpan RunTestEvery => TimeSpan.FromMinutes(10); + public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure; + public override string CustomK8sNamespace => nameof(TransientNodeTest).ToLowerInvariant(); + public override int EthereumAccountIndex => 201; + + private TestFile file = null!; + private ContentId cid = null!; + + private CodexNode UploadBootstapNode { get { return Nodes[0]; } } + private CodexNode DownloadBootstapNode { get { return Nodes[1]; } } + private CodexNode IntermediateNode { get { return Nodes[2]; } } + + [TestMoment(t: 0)] + public void UploadWithTransientNode() + { + file = FileManager.GenerateTestFile(10.MB()); + + NodeRunner.RunNode(UploadBootstapNode, (codexAccess, marketplaceAccess) => + { + cid = UploadFile(codexAccess.Node, file)!; + Assert.That(cid, Is.Not.Null); + + var resultFile = DownloadContent(IntermediateNode, cid); + file.AssertIsEqual(resultFile); + }); + } + + [TestMoment(t: MinuteFive)] + public void DownloadWithTransientNode() + { + NodeRunner.RunNode(DownloadBootstapNode, (codexAccess, marketplaceAccess) => + { + var resultFile = DownloadContent(codexAccess.Node, cid); + file.AssertIsEqual(resultFile); + }); + } + } +}