Adds filter option for selecting tests. Adds cleanup option for deleting deployment namespace.

This commit is contained in:
benbierens 2023-10-03 09:53:02 +02:00
parent b96751cd2c
commit 6fe9d38eb3
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 43 additions and 1 deletions

View File

@ -27,6 +27,12 @@ namespace ContinuousTests
[Uniform("target-duration", "td", "TARGETDURATION", false, "If greater than zero, runner will run for this many seconds before stopping.")]
public int TargetDurationSeconds { get; set; } = 0;
[Uniform("filter", "f", "FILTER", false, "If set, runs only tests whose names contain any of the filter strings. Comma-separated. Case sensitive.")]
public string Filter { get; set; } = string.Empty;
[Uniform("cleanup", "cl", "CLEANUP", false, "If set, the kubernetes namespace will be deleted after the test run has finished.")]
public bool Cleanup { get; set; } = false;
public CodexDeployment CodexDeployment { get; set; } = null!;
}

View File

@ -46,7 +46,13 @@ namespace ContinuousTests
ClearAllCustomNamespaces(allTests, overviewLog);
var testLoops = allTests.Select(t => new TestLoop(entryPointFactory, taskFactory, config, overviewLog, t.GetType(), t.RunTestEvery, startupChecker, cancelToken)).ToArray();
var filteredTests = FilterTests(allTests, overviewLog);
if (!filteredTests.Any())
{
overviewLog.Log("No tests selected.");
return;
}
var testLoops = filteredTests.Select(t => new TestLoop(entryPointFactory, taskFactory, config, overviewLog, t.GetType(), t.RunTestEvery, startupChecker, cancelToken)).ToArray();
foreach (var testLoop in testLoops)
{
@ -62,6 +68,24 @@ namespace ContinuousTests
overviewLog.Log("Cancelling all test-loops...");
taskFactory.WaitAll();
overviewLog.Log("All tasks cancelled.");
PerformCleanup(overviewLog);
}
private ContinuousTest[] FilterTests(ContinuousTest[] allTests, ILog log)
{
log.Log($"Available tests: {string.Join(", ", allTests.Select(r => r.Name))}");
var result = allTests.ToArray();
var filters = config.Filter.Split(",", StringSplitOptions.RemoveEmptyEntries);
if (filters.Any())
{
log.Log($"Applying filters: {string.Join(", ", filters)}");
result = allTests.Where(t => filters.Any(f => t.Name.Contains(f))).ToArray();
}
log.Log($"Selected for running: {string.Join(", ", result.Select(r => r.Name))}");
return result;
}
private void WaitUntilFinished(LogSplitter overviewLog, StatusLog statusLog, DateTime startTime, TestLoop[] testLoops)
@ -107,5 +131,15 @@ namespace ContinuousTests
var entryPoint = entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, test.CustomK8sNamespace, log);
entryPoint.Tools.CreateWorkflow().DeleteNamespacesStartingWith(test.CustomK8sNamespace);
}
private void PerformCleanup(ILog log)
{
if (!config.Cleanup) return;
log.Log("Cleaning up test namespace...");
var entryPoint = entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath, config.CodexDeployment.Metadata.KubeNamespace, log);
entryPoint.Decommission(deleteKubernetesResources: true, deleteTrackedFiles: true);
log.Log("Cleanup finished.");
}
}
}

View File

@ -2,6 +2,7 @@
using Core;
using DistTestCore.Logs;
using Logging;
using Newtonsoft.Json;
namespace ContinuousTests
{
@ -45,6 +46,7 @@ namespace ContinuousTests
foreach (var vars in codexVars) log.Log(vars.ToString());
log.Log("");
}
log.Log($"Deployment metadata: {JsonConvert.SerializeObject(deployment.Metadata)}");
log.Log("");
}