diff --git a/Tests/CodexContinuousTests/ContinuousTestRunner.cs b/Tests/CodexContinuousTests/ContinuousTestRunner.cs index 7e4ffd9..22d6ea4 100644 --- a/Tests/CodexContinuousTests/ContinuousTestRunner.cs +++ b/Tests/CodexContinuousTests/ContinuousTestRunner.cs @@ -57,7 +57,7 @@ namespace ContinuousTests } else { - var testLoops = filteredTests.Select(t => new TestLoop(entryPointFactory, taskFactory, config, overviewLog, t.GetType(), t.RunTestEvery, startupChecker, cancelToken)).ToArray(); + var testLoops = filteredTests.Select(t => new TestLoop(entryPointFactory, taskFactory, config, overviewLog, statusLog, t.GetType(), t.RunTestEvery, startupChecker, cancelToken)).ToArray(); foreach (var testLoop in testLoops) { @@ -124,7 +124,8 @@ namespace ContinuousTests var result = new Dictionary(); foreach (var testLoop in testLoops) { - result.Add($"ctest-{testLoop.Name}", $"passes: {testLoop.NumberOfPasses} - failures: {testLoop.NumberOfFailures}"); + result.Add("testname", testLoop.Name); + result.Add($"summary", $"passes: {testLoop.NumberOfPasses} - failures: {testLoop.NumberOfFailures}"); } return result; } diff --git a/Tests/CodexContinuousTests/SingleTestRun.cs b/Tests/CodexContinuousTests/SingleTestRun.cs index f86e502..213618c 100644 --- a/Tests/CodexContinuousTests/SingleTestRun.cs +++ b/Tests/CodexContinuousTests/SingleTestRun.cs @@ -16,6 +16,7 @@ namespace ContinuousTests private readonly TaskFactory taskFactory; private readonly Configuration config; private readonly ILog overviewLog; + private readonly StatusLog statusLog; private readonly TestHandle handle; private readonly CancellationToken cancelToken; private readonly ICodexNode[] nodes; @@ -23,11 +24,12 @@ namespace ContinuousTests private readonly string testName; private static int failureCount = 0; - public SingleTestRun(EntryPointFactory entryPointFactory, TaskFactory taskFactory, Configuration config, ILog overviewLog, TestHandle handle, StartupChecker startupChecker, CancellationToken cancelToken) + public SingleTestRun(EntryPointFactory entryPointFactory, TaskFactory taskFactory, Configuration config, ILog overviewLog, StatusLog statusLog, TestHandle handle, StartupChecker startupChecker, CancellationToken cancelToken) { this.taskFactory = taskFactory; this.config = config; this.overviewLog = overviewLog; + this.statusLog = statusLog; this.handle = handle; this.cancelToken = cancelToken; testName = handle.Test.GetType().Name; @@ -63,13 +65,15 @@ namespace ContinuousTests private void RunTest(Action resultHandler) { var testStart = DateTime.UtcNow; - + TimeSpan duration = TimeSpan.Zero; + try { RunTestMoments(); + duration = DateTime.UtcNow - testStart; - var duration = DateTime.UtcNow - testStart; OverviewLog($" > Test passed. ({Time.FormatDuration(duration)})"); + UpdateStatusLogPassed(testStart, duration); if (!config.KeepPassedTestLogs) { @@ -81,6 +85,7 @@ namespace ContinuousTests { fixtureLog.Error("Test run failed with exception: " + ex); fixtureLog.MarkAsFailed(); + UpdateStatusLogFailed(testStart, duration, ex.ToString()); DownloadContainerLogs(testStart); @@ -170,6 +175,26 @@ namespace ContinuousTests throw new Exception(exceptionsMessage); } + private void UpdateStatusLogFailed(DateTime testStart, TimeSpan duration, string error) + { + statusLog.ConcludeTest("Failed", duration, CreateStatusLogData(testStart, error)); + } + + private void UpdateStatusLogPassed(DateTime testStart, TimeSpan duration) + { + statusLog.ConcludeTest("Passed", duration, CreateStatusLogData(testStart, "OK")); + } + + private Dictionary CreateStatusLogData(DateTime testStart, string message) + { + return new Dictionary + { + { "teststart", testStart.ToString("o") }, + { "testname", testName }, + { "message", message } + }; + } + private string GetCombinedExceptionsMessage(Exception[] exceptions) { return string.Join(Environment.NewLine, exceptions.Select(ex => ex.ToString())); diff --git a/Tests/CodexContinuousTests/TestLoop.cs b/Tests/CodexContinuousTests/TestLoop.cs index 6c1157a..afa438b 100644 --- a/Tests/CodexContinuousTests/TestLoop.cs +++ b/Tests/CodexContinuousTests/TestLoop.cs @@ -1,4 +1,5 @@ -using Logging; +using DistTestCore.Logs; +using Logging; namespace ContinuousTests { @@ -8,6 +9,7 @@ namespace ContinuousTests private readonly TaskFactory taskFactory; private readonly Configuration config; private readonly ILog overviewLog; + private readonly StatusLog statusLog; private readonly Type testType; private readonly TimeSpan runsEvery; private readonly StartupChecker startupChecker; @@ -15,12 +17,13 @@ namespace ContinuousTests private readonly EventWaitHandle runFinishedHandle = new EventWaitHandle(true, EventResetMode.ManualReset); private static object testLock = new object(); - public TestLoop(EntryPointFactory entryPointFactory, TaskFactory taskFactory, Configuration config, ILog overviewLog, Type testType, TimeSpan runsEvery, StartupChecker startupChecker, CancellationToken cancelToken) + public TestLoop(EntryPointFactory entryPointFactory, TaskFactory taskFactory, Configuration config, ILog overviewLog, StatusLog statusLog, Type testType, TimeSpan runsEvery, StartupChecker startupChecker, CancellationToken cancelToken) { this.entryPointFactory = entryPointFactory; this.taskFactory = taskFactory; this.config = config; this.overviewLog = overviewLog; + this.statusLog = statusLog; this.testType = testType; this.runsEvery = runsEvery; this.startupChecker = startupChecker; @@ -73,7 +76,7 @@ namespace ContinuousTests { var test = (ContinuousTest)Activator.CreateInstance(testType)!; var handle = new TestHandle(test); - var run = new SingleTestRun(entryPointFactory, taskFactory, config, overviewLog, handle, startupChecker, cancelToken); + var run = new SingleTestRun(entryPointFactory, taskFactory, config, overviewLog, statusLog, handle, startupChecker, cancelToken); runFinishedHandle.Reset(); run.Run(runFinishedHandle, result => diff --git a/Tests/DistTestCore/Logs/StatusLog.cs b/Tests/DistTestCore/Logs/StatusLog.cs index b7ce891..bb41d0f 100644 --- a/Tests/DistTestCore/Logs/StatusLog.cs +++ b/Tests/DistTestCore/Logs/StatusLog.cs @@ -1,5 +1,6 @@ using Logging; using Newtonsoft.Json; +using Utils; namespace DistTestCore.Logs { @@ -15,6 +16,11 @@ namespace DistTestCore.Logs fixtureName = NameUtils.GetRawFixtureName(); } + public void ConcludeTest(string resultStatus, TimeSpan testDuration, Dictionary data) + { + ConcludeTest(resultStatus, Time.FormatDuration(testDuration), data); + } + public void ConcludeTest(string resultStatus, string testDuration, Dictionary data) { data.Add("timestamp", DateTime.UtcNow.ToString("o")); @@ -23,7 +29,7 @@ namespace DistTestCore.Logs data.Add("testid", NameUtils.GetTestId()); data.Add("category", NameUtils.GetCategoryName()); data.Add("fixturename", fixtureName); - data.Add("testname", NameUtils.GetTestMethodName()); + if (!data.ContainsKey("testname")) data.Add("testname", NameUtils.GetTestMethodName()); data.Add("testduration", testDuration); Write(data); }