2023-06-28 15:11:20 +02:00
|
|
|
|
using DistTestCore;
|
|
|
|
|
using Logging;
|
2023-06-25 11:06:47 +02:00
|
|
|
|
|
|
|
|
|
namespace ContinuousTests
|
2023-06-21 08:28:40 +02:00
|
|
|
|
{
|
2023-06-25 09:53:10 +02:00
|
|
|
|
public class ContinuousTestRunner
|
2023-06-21 08:28:40 +02:00
|
|
|
|
{
|
2023-06-28 15:11:20 +02:00
|
|
|
|
private readonly K8sFactory k8SFactory = new K8sFactory();
|
2023-06-21 08:28:40 +02:00
|
|
|
|
private readonly ConfigLoader configLoader = new ConfigLoader();
|
2023-06-21 09:27:59 +02:00
|
|
|
|
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-21 10:06:54 +02:00
|
|
|
|
|
2023-06-28 16:19:37 +02:00
|
|
|
|
public ContinuousTestRunner(string[] args, CancellationToken cancelToken)
|
2023-06-21 10:06:54 +02:00
|
|
|
|
{
|
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-21 10:06:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-25 09:53:10 +02:00
|
|
|
|
public void Run()
|
2023-06-21 08:28:40 +02:00
|
|
|
|
{
|
2023-06-25 09:53:10 +02:00
|
|
|
|
startupChecker.Check();
|
2023-06-21 08:28:40 +02:00
|
|
|
|
|
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);
|
|
|
|
|
|
2023-07-20 13:37:11 +02:00
|
|
|
|
StartLogDownloader(taskFactory);
|
|
|
|
|
|
2023-06-28 16:19:37 +02:00
|
|
|
|
var testLoops = allTests.Select(t => new TestLoop(taskFactory, config, overviewLog, t.GetType(), t.RunTestEvery, cancelToken)).ToArray();
|
2023-06-21 08:28:40 +02:00
|
|
|
|
|
2023-06-28 16:19:37 +02:00
|
|
|
|
foreach (var testLoop in testLoops)
|
2023-06-21 08:28:40 +02:00
|
|
|
|
{
|
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();
|
2023-06-29 13:39:05 +02:00
|
|
|
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
2023-06-21 08:28:40 +02:00
|
|
|
|
}
|
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-23 11:38:30 +02:00
|
|
|
|
}
|
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}'...");
|
2023-06-30 09:09:59 +02:00
|
|
|
|
var (workflowCreator, _) = k8SFactory.CreateFacilities(config.KubeConfigFile, config.LogPath, config.DataPath, test.CustomK8sNamespace, new DefaultTimeSet(), log, config.RunnerLocation);
|
2023-06-28 15:11:20 +02:00
|
|
|
|
workflowCreator.CreateWorkflow().DeleteTestResources();
|
|
|
|
|
}
|
2023-07-20 13:37:11 +02:00
|
|
|
|
|
|
|
|
|
private void StartLogDownloader(TaskFactory taskFactory)
|
|
|
|
|
{
|
|
|
|
|
if (!config.DownloadContainerLogs) return;
|
|
|
|
|
|
|
|
|
|
var path = Path.Combine(config.LogPath, "containers");
|
|
|
|
|
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
|
|
|
|
|
|
|
|
|
var (_, lifecycle) = k8SFactory.CreateFacilities(config.KubeConfigFile, config.LogPath, config.DataPath, config.CodexDeployment.Metadata.KubeNamespace, new DefaultTimeSet(), new NullLog(), config.RunnerLocation);
|
|
|
|
|
var downloader = new ContinuousLogDownloader(lifecycle, config.CodexDeployment, path, cancelToken);
|
|
|
|
|
|
|
|
|
|
taskFactory.Run(downloader.Run);
|
|
|
|
|
}
|
2023-06-21 10:06:54 +02:00
|
|
|
|
}
|
2023-06-21 08:28:40 +02:00
|
|
|
|
}
|