Sleep per test and per all-tests

This commit is contained in:
benbierens 2023-06-21 10:34:29 +02:00
parent c5c54f5963
commit 0d9918b401
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 37 additions and 19 deletions

View File

@ -41,7 +41,7 @@ namespace ContinuousTests
result = ContinuousTestResult.Failed;
}
Thread.Sleep(config.SleepSecondsPerTest * 1000);
Thread.Sleep(config.SleepSecondsPerSingleTest * 1000);
}
return result;
}

View File

@ -6,7 +6,8 @@ namespace ContinuousTests
{
public string LogPath { get; set; } = string.Empty;
public string[] CodexUrls { get; set; } = Array.Empty<string>();
public int SleepSecondsPerTest { get; set; }
public int SleepSecondsPerSingleTest { get; set; }
public int SleepSecondsPerAllTests { get; set; }
}
public class ConfigLoader
@ -16,9 +17,6 @@ namespace ContinuousTests
public Configuration Load()
{
var config = Read();
//config.LogPath = "logs";
//config.SleepSecondsPerTest = 10;
//config.CodexUrls = new string[] { "http://localhost:8080", "http://localhost:8081" };
Validate(config);
return config;
@ -39,33 +37,53 @@ namespace ContinuousTests
var logPath = Environment.GetEnvironmentVariable("LOGPATH");
var codexUrls = Environment.GetEnvironmentVariable("CODEXURLS");
var sleep = Environment.GetEnvironmentVariable("SLEEPSECONDSPERTEST");
var sleepPerSingle = Environment.GetEnvironmentVariable("SLEEPSECONDSPERSINGLETEST");
var sleepPerAll = Environment.GetEnvironmentVariable("SLEEPSECONDSPERALLTESTS");
if (!string.IsNullOrEmpty(logPath) && !string.IsNullOrEmpty(codexUrls) && !string.IsNullOrEmpty(sleep))
if (!string.IsNullOrEmpty(logPath) &&
!string.IsNullOrEmpty(codexUrls) &&
!string.IsNullOrEmpty(sleepPerSingle) &&
!string.IsNullOrEmpty(sleepPerAll))
{
var urls = codexUrls.Split(';', StringSplitOptions.RemoveEmptyEntries);
int ms;
if (int.TryParse(sleep, out ms))
int secondsSingle;
int secondsAll;
if (int.TryParse(sleepPerSingle, out secondsSingle) && int.TryParse(sleepPerAll, out secondsAll))
{
if (urls.Length > 0)
{
return new Configuration { LogPath = logPath, CodexUrls = urls, SleepSecondsPerTest = ms };
return new Configuration
{
LogPath = logPath,
CodexUrls = urls,
SleepSecondsPerSingleTest = secondsSingle,
SleepSecondsPerAllTests = secondsAll
};
}
}
}
var nl = Environment.NewLine;
throw new Exception($"Unable to load configuration from '{filename}', and " +
$"unable to load configuration from environment variables 'LOGPATH' and 'CODEXURLS', and 'SLEEPSECONDSPERTEST'. " +
$"(semi-colon-separated URLs) " +
$"Create the configuration file or set the environment veriables.");
$"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 +
nl);
}
private void Validate(Configuration configuration)
{
if (configuration.SleepSecondsPerTest < 10)
if (configuration.SleepSecondsPerSingleTest < 1)
{
Console.WriteLine("Warning: configuration.SleepMsPerTest was less than 10 seconds. Using 10 seconds instead!");
configuration.SleepSecondsPerTest = 10;
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))

View File

@ -17,7 +17,7 @@ namespace ContinuousTests
while (true)
{
var log = new FixtureLog(new LogConfig(config.LogPath, false), "StartupChecks");
var log = new FixtureLog(new LogConfig(config.LogPath, false), "ContinuousTestsRun");
var allTestsRun = new AllTestsRun(config, log, testFactory);
var result = ContinuousTestResult.Passed;
@ -35,13 +35,13 @@ namespace ContinuousTests
log.MarkAsFailed();
}
Thread.Sleep(config.SleepSecondsPerTest * 1000);
Thread.Sleep(config.SleepSecondsPerSingleTest * 1000);
}
}
private void StartupChecks(Configuration config)
{
var log = new FixtureLog(new LogConfig(config.LogPath, false), "ContinuousTestsRun");
var log = new FixtureLog(new LogConfig(config.LogPath, false), "StartupChecks");
log.Log("Starting continuous test run...");
log.Log("Checking configuration...");
PreflightCheck(config);