diff --git a/ContinuousTests/AllTestsRun.cs b/ContinuousTests/AllTestsRun.cs index 661b6af..d825cbe 100644 --- a/ContinuousTests/AllTestsRun.cs +++ b/ContinuousTests/AllTestsRun.cs @@ -1,6 +1,4 @@ -using DistTestCore; -using DistTestCore.Codex; -using Logging; +using Logging; using Utils; namespace ContinuousTests @@ -33,6 +31,7 @@ namespace ContinuousTests { singleTestRun.Run(); log.Log($"'{test.Name}' = Passed"); + if (!config.KeepPassedTestLogs) testLog.Delete(); } catch { @@ -43,54 +42,7 @@ namespace ContinuousTests Thread.Sleep(config.SleepSecondsPerSingleTest * 1000); } - return result; - } - } - public class SingleTestRun - { - private readonly CodexNodeFactory codexNodeFactory = new CodexNodeFactory(); - private readonly Configuration config; - private readonly ContinuousTest test; - private readonly CodexNode[] nodes; - private readonly FileManager fileManager; - - public SingleTestRun(Configuration config, ContinuousTest test, BaseLog testLog) - { - this.config = config; - this.test = test; - - nodes = CreateRandomNodes(test.RequiredNumberOfNodes, testLog); - fileManager = new FileManager(testLog, new DistTestCore.Configuration()); - - test.Initialize(nodes, testLog, fileManager); - } - - public void Run() - { - test.Run(); - } - - public void TearDown() - { - test.Initialize(null!, null!, null!); - fileManager.DeleteAllTestFiles(); - } - - private CodexNode[] CreateRandomNodes(int number, BaseLog testLog) - { - var urls = SelectRandomUrls(number); - return codexNodeFactory.Create(urls, testLog, test.TimeSet); - } - - private string[] SelectRandomUrls(int number) - { - var urls = config.CodexUrls.ToList(); - var result = new string[number]; - for (var i = 0; i < number; i++) - { - result[i] = urls.PickOneRandom(); - } return result; } } diff --git a/ContinuousTests/Configuration.cs b/ContinuousTests/Configuration.cs index e51f4b9..4e6278e 100644 --- a/ContinuousTests/Configuration.cs +++ b/ContinuousTests/Configuration.cs @@ -8,6 +8,7 @@ namespace ContinuousTests public string[] CodexUrls { get; set; } = Array.Empty(); public int SleepSecondsPerSingleTest { get; set; } public int SleepSecondsPerAllTests { get; set; } + public bool KeepPassedTestLogs { get; set; } } public class ConfigLoader @@ -39,6 +40,7 @@ namespace ContinuousTests var codexUrls = Environment.GetEnvironmentVariable("CODEXURLS"); var sleepPerSingle = Environment.GetEnvironmentVariable("SLEEPSECONDSPERSINGLETEST"); var sleepPerAll = Environment.GetEnvironmentVariable("SLEEPSECONDSPERALLTESTS"); + var keep = Environment.GetEnvironmentVariable("KEEPPASSEDTESTLOGS"); if (!string.IsNullOrEmpty(logPath) && !string.IsNullOrEmpty(codexUrls) && @@ -57,7 +59,8 @@ namespace ContinuousTests LogPath = logPath, CodexUrls = urls, SleepSecondsPerSingleTest = secondsSingle, - SleepSecondsPerAllTests = secondsAll + SleepSecondsPerAllTests = secondsAll, + KeepPassedTestLogs = keep == "1" }; } } @@ -65,11 +68,12 @@ namespace ContinuousTests var nl = Environment.NewLine; 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 + - $"'CODEXURLS' = Semi-colon separated URLs to codex APIs. e.g. 'https://hostaddr_one:port;https://hostaddr_two:port'" + nl + - $"'SLEEPSECONDSPERSINGLETEST' = Seconds to sleep after each individual test." + nl + - $"'SLEEPSECONDSPERALLTESTS' = Seconds to sleep after all tests, before starting again." + nl + + "unable to load configuration from environment variables. " + nl + + "'LOGPATH' = Path where log files will be saved." + nl + + "'CODEXURLS' = Semi-colon separated URLs to codex APIs. e.g. 'https://hostaddr_one:port;https://hostaddr_two:port'" + 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); } diff --git a/ContinuousTests/ContinuousTestRunner.cs b/ContinuousTests/ContinuousTestRunner.cs index bc03aca..c829a1c 100644 --- a/ContinuousTests/ContinuousTestRunner.cs +++ b/ContinuousTests/ContinuousTestRunner.cs @@ -34,6 +34,10 @@ namespace ContinuousTests { log.MarkAsFailed(); } + if (!config.KeepPassedTestLogs && result == ContinuousTestResult.Passed) + { + log.DeleteFolder(); + } Thread.Sleep(config.SleepSecondsPerSingleTest * 1000); } diff --git a/ContinuousTests/SingleTestRun.cs b/ContinuousTests/SingleTestRun.cs new file mode 100644 index 0000000..e7c39a7 --- /dev/null +++ b/ContinuousTests/SingleTestRun.cs @@ -0,0 +1,55 @@ +using DistTestCore.Codex; +using DistTestCore; +using Logging; +using Utils; + +namespace ContinuousTests +{ + public class SingleTestRun + { + private readonly CodexNodeFactory codexNodeFactory = new CodexNodeFactory(); + private readonly Configuration config; + private readonly ContinuousTest test; + private readonly CodexNode[] nodes; + private readonly FileManager fileManager; + + public SingleTestRun(Configuration config, ContinuousTest test, BaseLog testLog) + { + this.config = config; + this.test = test; + + nodes = CreateRandomNodes(test.RequiredNumberOfNodes, testLog); + fileManager = new FileManager(testLog, new DistTestCore.Configuration()); + + test.Initialize(nodes, testLog, fileManager); + } + + public void Run() + { + test.Run(); + } + + public void TearDown() + { + test.Initialize(null!, null!, null!); + fileManager.DeleteAllTestFiles(); + } + + private CodexNode[] CreateRandomNodes(int number, BaseLog testLog) + { + var urls = SelectRandomUrls(number); + return codexNodeFactory.Create(urls, testLog, test.TimeSet); + } + + private string[] SelectRandomUrls(int number) + { + var urls = config.CodexUrls.ToList(); + var result = new string[number]; + for (var i = 0; i < number; i++) + { + result[i] = urls.PickOneRandom(); + } + return result; + } + } +} diff --git a/Logging/BaseLog.cs b/Logging/BaseLog.cs index 6a35597..2c69f9c 100644 --- a/Logging/BaseLog.cs +++ b/Logging/BaseLog.cs @@ -58,6 +58,11 @@ namespace Logging replacements.Add(new BaseLogStringReplacement(from, to)); } + public void Delete() + { + File.Delete(LogFile.FullFilename); + } + private string ApplyReplacements(string str) { foreach (var replacement in replacements) diff --git a/Logging/FixtureLog.cs b/Logging/FixtureLog.cs index 53eae10..cc5ea87 100644 --- a/Logging/FixtureLog.cs +++ b/Logging/FixtureLog.cs @@ -23,6 +23,11 @@ namespace Logging return new TestLog(fullName, config.DebugEnabled, name); } + public void DeleteFolder() + { + Directory.Delete(fullName, true); + } + protected override LogFile CreateLogFile() { return new LogFile(fullName, "log");