2
0
mirror of synced 2025-01-12 17:44:08 +00:00
cs-codex-dist-tests/ContinuousTests/ContinuousTestRunner.cs

66 lines
2.5 KiB
C#
Raw Normal View History

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