cs-codex-dist-tests/ContinuousTests/ContinuousTestRunner.cs

66 lines
2.5 KiB
C#
Raw Normal View History

2023-06-28 13:11:20 +00:00
using DistTestCore;
using Logging;
2023-06-25 09:06:47 +00:00
namespace ContinuousTests
{
2023-06-25 07:53:10 +00:00
public class ContinuousTestRunner
{
2023-06-28 13:11:20 +00:00
private readonly K8sFactory k8SFactory = new K8sFactory();
private readonly ConfigLoader configLoader = new ConfigLoader();
private readonly TestFactory testFactory = new TestFactory();
2023-06-25 07:53:10 +00:00
private readonly Configuration config;
private readonly StartupChecker startupChecker;
2023-06-28 14:19:37 +00:00
private readonly CancellationToken cancelToken;
2023-06-28 14:19:37 +00:00
public ContinuousTestRunner(string[] args, CancellationToken cancelToken)
{
2023-06-26 12:44:21 +00:00
config = configLoader.Load(args);
2023-07-07 06:52:53 +00:00
startupChecker = new StartupChecker(config, cancelToken);
2023-06-28 14:19:37 +00:00
this.cancelToken = cancelToken;
}
2023-06-25 07:53:10 +00:00
public void Run()
{
2023-06-25 07:53:10 +00:00
startupChecker.Check();
2023-06-28 14:19:37 +00:00
var taskFactory = new TaskFactory();
2023-06-25 09:06:47 +00:00
var overviewLog = new FixtureLog(new LogConfig(config.LogPath, false), "Overview");
2023-06-27 08:16:59 +00:00
overviewLog.Log("Continuous tests starting...");
2023-06-25 07:53:10 +00:00
var allTests = testFactory.CreateTests();
2023-06-28 13:11:20 +00:00
ClearAllCustomNamespaces(allTests, overviewLog);
2023-06-28 14:19:37 +00:00
var testLoops = allTests.Select(t => new TestLoop(taskFactory, config, overviewLog, t.GetType(), t.RunTestEvery, cancelToken)).ToArray();
2023-06-28 14:19:37 +00:00
foreach (var testLoop in testLoops)
{
2023-06-29 08:23:04 +00:00
if (cancelToken.IsCancellationRequested) break;
2023-06-28 14:19:37 +00:00
overviewLog.Log("Launching test-loop for " + testLoop.Name);
testLoop.Begin();
Thread.Sleep(TimeSpan.FromSeconds(5));
}
2023-06-27 08:16:59 +00:00
2023-06-29 08:23:04 +00:00
overviewLog.Log("Finished launching test-loops.");
2023-06-28 14:19:37 +00:00
cancelToken.WaitHandle.WaitOne();
overviewLog.Log("Cancelling all test-loops...");
taskFactory.WaitAll();
2023-06-29 08:23:04 +00:00
overviewLog.Log("All tasks cancelled.");
}
2023-06-28 13:11:20 +00:00
private void ClearAllCustomNamespaces(ContinuousTest[] allTests, FixtureLog log)
{
foreach (var test in allTests) ClearAllCustomNamespaces(test, log);
}
private void ClearAllCustomNamespaces(ContinuousTest test, FixtureLog log)
{
if (string.IsNullOrEmpty(test.CustomK8sNamespace)) return;
log.Log($"Clearing namespace '{test.CustomK8sNamespace}'...");
var (workflowCreator, _) = k8SFactory.CreateFacilities(config.KubeConfigFile, config.LogPath, config.DataPath, test.CustomK8sNamespace, new DefaultTimeSet(), log, config.RunnerLocation);
2023-06-28 13:11:20 +00:00
workflowCreator.CreateWorkflow().DeleteTestResources();
}
}
}