Adds status log to continuous tests
This commit is contained in:
parent
dabf836838
commit
453a1a35a2
|
@ -20,10 +20,14 @@ namespace ContinuousTests
|
|||
|
||||
public void Run()
|
||||
{
|
||||
var logConfig = new LogConfig(config.LogPath, false);
|
||||
var startTime = DateTime.UtcNow;
|
||||
|
||||
var overviewLog = new LogSplitter(
|
||||
new FixtureLog(new LogConfig(config.LogPath, false), DateTime.UtcNow, "Overview"),
|
||||
new FixtureLog(logConfig, startTime, "Overview"),
|
||||
new ConsoleLog()
|
||||
);
|
||||
var statusLog = new StatusLog(logConfig, startTime, "ContinuousTestRun");
|
||||
|
||||
overviewLog.Log("Initializing...");
|
||||
|
||||
|
@ -54,26 +58,41 @@ namespace ContinuousTests
|
|||
}
|
||||
|
||||
overviewLog.Log("Finished launching test-loops.");
|
||||
WaitUntilFinished(overviewLog);
|
||||
WaitUntilFinished(overviewLog, statusLog, startTime, testLoops);
|
||||
overviewLog.Log("Cancelling all test-loops...");
|
||||
taskFactory.WaitAll();
|
||||
overviewLog.Log("All tasks cancelled.");
|
||||
}
|
||||
|
||||
private void WaitUntilFinished(LogSplitter overviewLog)
|
||||
private void WaitUntilFinished(LogSplitter overviewLog, StatusLog statusLog, DateTime startTime, TestLoop[] testLoops)
|
||||
{
|
||||
var testDuration = Time.FormatDuration(DateTime.UtcNow - startTime);
|
||||
var testData = FormatTestRuns(testLoops);
|
||||
|
||||
if (config.TargetDurationSeconds > 0)
|
||||
{
|
||||
var targetDuration = TimeSpan.FromSeconds(config.TargetDurationSeconds);
|
||||
cancelToken.WaitHandle.WaitOne(targetDuration);
|
||||
overviewLog.Log($"Congratulations! The targer duration has been reached! ({Time.FormatDuration(targetDuration)})");
|
||||
statusLog.ConcludeTest("Passed", testDuration, testData);
|
||||
}
|
||||
else
|
||||
{
|
||||
cancelToken.WaitHandle.WaitOne();
|
||||
statusLog.ConcludeTest("Failed", testDuration, testData);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, string> FormatTestRuns(TestLoop[] testLoops)
|
||||
{
|
||||
var result = new Dictionary<string, string>();
|
||||
foreach (var testLoop in testLoops)
|
||||
{
|
||||
result.Add($"ctest-{testLoop.Name}", $"passes: {testLoop.NumberOfPasses} - failures: {testLoop.NumberOfFailures}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ClearAllCustomNamespaces(ContinuousTest[] allTests, ILog log)
|
||||
{
|
||||
foreach (var test in allTests) ClearAllCustomNamespaces(test, log);
|
||||
|
|
|
@ -38,13 +38,13 @@ namespace ContinuousTests
|
|||
nodes = CreateRandomNodes();
|
||||
}
|
||||
|
||||
public void Run(EventWaitHandle runFinishedHandle)
|
||||
public void Run(EventWaitHandle runFinishedHandle, Action<bool> resultHandler)
|
||||
{
|
||||
taskFactory.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
RunTest();
|
||||
RunTest(resultHandler);
|
||||
|
||||
entryPoint.Decommission(
|
||||
deleteKubernetesResources: false, // This would delete the continuous test net.
|
||||
|
@ -60,13 +60,14 @@ namespace ContinuousTests
|
|||
});
|
||||
}
|
||||
|
||||
private void RunTest()
|
||||
private void RunTest(Action<bool> resultHandler)
|
||||
{
|
||||
try
|
||||
{
|
||||
RunTestMoments();
|
||||
|
||||
if (!config.KeepPassedTestLogs) fixtureLog.Delete();
|
||||
resultHandler(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -74,6 +75,7 @@ namespace ContinuousTests
|
|||
fixtureLog.MarkAsFailed();
|
||||
|
||||
failureCount++;
|
||||
resultHandler(false);
|
||||
if (config.StopOnFailure > 0)
|
||||
{
|
||||
OverviewLog($"Failures: {failureCount} / {config.StopOnFailure}");
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace ContinuousTests
|
|||
}
|
||||
|
||||
public string Name { get; }
|
||||
public int NumberOfPasses { get; private set; }
|
||||
public int NumberOfFailures { get; private set; }
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
|
@ -35,6 +37,8 @@ namespace ContinuousTests
|
|||
{
|
||||
try
|
||||
{
|
||||
NumberOfPasses = 0;
|
||||
NumberOfFailures = 0;
|
||||
while (true)
|
||||
{
|
||||
WaitHandle.WaitAny(new[] { runFinishedHandle, cancelToken.WaitHandle });
|
||||
|
@ -65,7 +69,11 @@ namespace ContinuousTests
|
|||
var run = new SingleTestRun(entryPointFactory, taskFactory, config, overviewLog, handle, startupChecker, cancelToken);
|
||||
|
||||
runFinishedHandle.Reset();
|
||||
run.Run(runFinishedHandle);
|
||||
run.Run(runFinishedHandle, result =>
|
||||
{
|
||||
if (result) NumberOfPasses++;
|
||||
else NumberOfFailures++;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue