Deletes log files for tests and runs that passed.
This commit is contained in:
parent
0d9918b401
commit
ae5309c2b6
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace ContinuousTests
|
|||
public string[] CodexUrls { get; set; } = Array.Empty<string>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,10 @@ namespace ContinuousTests
|
|||
{
|
||||
log.MarkAsFailed();
|
||||
}
|
||||
if (!config.KeepPassedTestLogs && result == ContinuousTestResult.Passed)
|
||||
{
|
||||
log.DeleteFolder();
|
||||
}
|
||||
|
||||
Thread.Sleep(config.SleepSecondsPerSingleTest * 1000);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue