diff --git a/ContinuousTests/Configuration.cs b/ContinuousTests/Configuration.cs index b8b5223..3fdca13 100644 --- a/ContinuousTests/Configuration.cs +++ b/ContinuousTests/Configuration.cs @@ -36,25 +36,22 @@ namespace ContinuousTests catch { } } - var logPath = "logs";// Environment.GetEnvironmentVariable("LOGPATH"); - var codexDeploymentJson = "C:\\Users\\Ben\\Desktop\\codex-deployment.json"; //Environment.GetEnvironmentVariable("CODEXDEPLOYMENT"); - var sleepPerSingle = "10";// Environment.GetEnvironmentVariable("SLEEPSECONDSPERSINGLETEST"); - var sleepPerAll = "10";// Environment.GetEnvironmentVariable("SLEEPSECONDSPERALLTESTS"); - var keep = ""; // Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS"); + var logPath = Environment.GetEnvironmentVariable("LOGPATH"); + var dataPath = Environment.GetEnvironmentVariable("DATAPATH"); + var codexDeploymentJson = Environment.GetEnvironmentVariable("CODEXDEPLOYMENT"); + var keep = Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS"); if (!string.IsNullOrEmpty(logPath) && - !string.IsNullOrEmpty(codexDeploymentJson) && - !string.IsNullOrEmpty(sleepPerSingle) && - !string.IsNullOrEmpty(sleepPerAll)) + !string.IsNullOrEmpty(dataPath) && + !string.IsNullOrEmpty(codexDeploymentJson)) { try { return new Configuration { LogPath = logPath, + DataPath = dataPath, CodexDeployment = ParseCodexDeploymentJson(codexDeploymentJson), - //SleepSecondsPerSingleTest = Convert.ToInt32(sleepPerSingle), - //SleepSecondsPerAllTests = Convert.ToInt32(sleepPerAll), KeepPassedTestLogs = keep == "1" }; } @@ -68,29 +65,21 @@ namespace ContinuousTests throw new Exception($"Unable to load configuration from '{filename}', and " + "unable to load configuration from environment variables. " + nl + "'LOGPATH' = Path where log files will be saved." + nl + + "'DATAPATH' = Path where temporary data files will be saved." + nl + "'CODEXDEPLOYMENT' = Path to codex-deployment JSON file." + nl + - "'SLEEPSECONDSPERSINGLETEST' = Seconds to sleep after each individual test." + nl + - "'SLEEPSECONDSPERALLTESTS' = Seconds to sleep after all tests, before starting again." + nl + - "'KEEPPASSEDTESTLOGS' = (Optional, default: 0) Set to '1' to keep log files of tests that passed." + nl + nl); } private void Validate(Configuration configuration) { - //if (configuration.SleepSecondsPerSingleTest < 1) - //{ - // Console.WriteLine("Warning: configuration.SleepSecondsPerSingleTest was less than 1 seconds. Using 1 seconds instead!"); - // configuration.SleepSecondsPerSingleTest = 1; - //} - //if (configuration.SleepSecondsPerAllTests < 1) - //{ - // Console.WriteLine("Warning: configuration.SleepSecondsPerAllTests was less than 10 seconds. Using 10 seconds instead!"); - // configuration.SleepSecondsPerAllTests = 10; - //} - if (string.IsNullOrEmpty(configuration.LogPath)) { - throw new Exception($"Unvalid logpath set: '{configuration.LogPath}'"); + throw new Exception($"Invalid LogPath set: '{configuration.LogPath}'"); + } + + if (string.IsNullOrEmpty(configuration.DataPath)) + { + throw new Exception($"Invalid DataPath set: '{configuration.DataPath}'"); } if (configuration.CodexDeployment == null || !configuration.CodexDeployment.CodexContainers.Any()) diff --git a/ContinuousTests/ContinuousTest.cs b/ContinuousTests/ContinuousTest.cs index 4df6dae..c278aad 100644 --- a/ContinuousTests/ContinuousTest.cs +++ b/ContinuousTests/ContinuousTest.cs @@ -12,7 +12,9 @@ namespace ContinuousTests public abstract class ContinuousTest { protected const int Zero = 0; - protected const int HourOne = 3600; + protected const int MinuteOne = 60; + protected const int MinuteFive = MinuteOne * 5; + protected const int HourOne = MinuteOne * 60; protected const int DayOne = HourOne * 24; protected const int DayThree = DayOne * 3; diff --git a/ContinuousTests/ContinuousTestRunner.cs b/ContinuousTests/ContinuousTestRunner.cs index b1915e5..a2522aa 100644 --- a/ContinuousTests/ContinuousTestRunner.cs +++ b/ContinuousTests/ContinuousTestRunner.cs @@ -25,7 +25,7 @@ t.Begin(); } - Thread.Sleep(TimeSpan.MaxValue); + while (true) Thread.Sleep((2 ^ 31) - 1); } } } diff --git a/ContinuousTests/SingleTestRun.cs b/ContinuousTests/SingleTestRun.cs index f7740fe..8e384d3 100644 --- a/ContinuousTests/SingleTestRun.cs +++ b/ContinuousTests/SingleTestRun.cs @@ -15,6 +15,7 @@ namespace ContinuousTests private readonly CodexNode[] nodes; private readonly FileManager fileManager; private readonly FixtureLog fixtureLog; + private readonly string dataFolder; public SingleTestRun(Configuration config, TestHandle handle) { @@ -25,6 +26,7 @@ namespace ContinuousTests fixtureLog = new FixtureLog(new LogConfig(config.LogPath, false), testName); nodes = CreateRandomNodes(handle.Test.RequiredNumberOfNodes); + dataFolder = config.DataPath + "-" + Guid.NewGuid(); fileManager = new FileManager(fixtureLog, CreateFileManagerConfiguration()); } @@ -44,16 +46,16 @@ namespace ContinuousTests fixtureLog.MarkAsFailed(); } fileManager.DeleteAllTestFiles(); + Directory.Delete(dataFolder, true); }); } private void RunTest() { var earliestMoment = handle.GetEarliestMoment(); - var lastMoment = handle.GetLastMoment(); var t = earliestMoment; - while (t <= lastMoment) + while (true) { RunMoment(t); @@ -72,11 +74,15 @@ namespace ContinuousTests } else { - Log(" > Completed last test moment. Test ended."); + if (exceptions.Any()) + { + Log(" > Completed last test moment. Test failed."); + throw exceptions.First(); + } + Log(" > Completed last test moment. Test passed."); + return; } } - - if (exceptions.Any()) throw exceptions.First(); } private void RunMoment(int t) @@ -130,7 +136,7 @@ namespace ContinuousTests private DistTestCore.Configuration CreateFileManagerConfiguration() { - return new DistTestCore.Configuration(null, string.Empty, false, config.DataPath + Guid.NewGuid(), + return new DistTestCore.Configuration(null, string.Empty, false, dataFolder, CodexLogLevel.Error, TestRunnerLocation.ExternalToCluster); } } diff --git a/ContinuousTests/TestHandle.cs b/ContinuousTests/TestHandle.cs index 6decdc0..7071d17 100644 --- a/ContinuousTests/TestHandle.cs +++ b/ContinuousTests/TestHandle.cs @@ -31,7 +31,7 @@ namespace ContinuousTests public int? GetNextMoment(int currentMoment) { - var remainingMoments = moments.Where(m => m.Moment >= currentMoment).ToArray(); + var remainingMoments = moments.Where(m => m.Moment > currentMoment).ToArray(); if (!remainingMoments.Any()) return null; return remainingMoments.Min(m => m.Moment); } @@ -71,6 +71,8 @@ namespace ContinuousTests { Method = method; Moment = moment; + + if (moment < 0) throw new Exception("Moment must be zero or greater."); } public MethodInfo Method { get; } diff --git a/ContinuousTests/Tests/MarketplaceTest.cs b/ContinuousTests/Tests/MarketplaceTest.cs index e82e1f7..03243c8 100644 --- a/ContinuousTests/Tests/MarketplaceTest.cs +++ b/ContinuousTests/Tests/MarketplaceTest.cs @@ -2,25 +2,24 @@ namespace ContinuousTests.Tests { - public class MarketplaceTest : ContinuousTest - { - public override int RequiredNumberOfNodes => 1; - public override TimeSpan RunTestEvery => TimeSpan.FromDays(1); - public override TestFailMode TestFailMode => TestFailMode.AlwaysRunAllMoments; + //public class MarketplaceTest : ContinuousTest + //{ + // public override int RequiredNumberOfNodes => 1; + // public override TimeSpan RunTestEvery => TimeSpan.FromDays(1); + // public override TestFailMode TestFailMode => TestFailMode.AlwaysRunAllMoments; - [TestMoment(t: Zero)] - public void NodePostsStorageRequest() - { - //var c = new KubernetesWorkflow.WorkflowCreator(Log, new KubernetesWorkflow.Configuration()); - //var flow = c.CreateWorkflow(); - //var rc = flow.Start(10, KubernetesWorkflow.Location.Unspecified, new CodexContainerRecipe(), new KubernetesWorkflow.StartupConfig()); - } + // [TestMoment(t: Zero)] + // public void NodePostsStorageRequest() + // { + // //var c = new KubernetesWorkflow.WorkflowCreator(Log, new KubernetesWorkflow.Configuration()); + // //var flow = c.CreateWorkflow(); + // //var rc = flow.Start(10, KubernetesWorkflow.Location.Unspecified, new CodexContainerRecipe(), new KubernetesWorkflow.StartupConfig()); + // } - [TestMoment(t: DayThree)] - public void NodeDownloadsStorageRequestData() - { - - } - } + // [TestMoment(t: DayThree)] + // public void NodeDownloadsStorageRequestData() + // { + // } + //} } diff --git a/ContinuousTests/Tests/TwoClientTest.cs b/ContinuousTests/Tests/TwoClientTest.cs index 13bc631..e6cbc1a 100644 --- a/ContinuousTests/Tests/TwoClientTest.cs +++ b/ContinuousTests/Tests/TwoClientTest.cs @@ -3,20 +3,30 @@ using NUnit.Framework; namespace ContinuousTests.Tests { - //public class TwoClientTest : ContinuousTest - //{ - // public override int RequiredNumberOfNodes => 2; + public class TwoClientTest : ContinuousTest + { + public override int RequiredNumberOfNodes => 2; + public override TimeSpan RunTestEvery => TimeSpan.FromHours(1); + public override TestFailMode TestFailMode => TestFailMode.StopAfterFirstFailure; - // public override void Run() - // { - // var file = FileManager.GenerateTestFile(10.MB()); + private ContentId? cid; + private TestFile file = null!; - // var cid = UploadFile(Nodes[0], file); - // Assert.That(cid, Is.Not.Null); + [TestMoment(t: Zero)] + public void UploadTestFile() + { + file = FileManager.GenerateTestFile(10.MB()); - // var dl = DownloadContent(Nodes[1], cid!); + cid = UploadFile(Nodes[0], file); + Assert.That(cid, Is.Not.Null); + } - // file.AssertIsEqual(dl); - // } - //} + [TestMoment(t: MinuteFive)] + public void DownloadTestFile() + { + var dl = DownloadContent(Nodes[1], cid!); + + file.AssertIsEqual(dl); + } + } }