diff --git a/ContinuousTests/ContinuousTestRunner.cs b/ContinuousTests/ContinuousTestRunner.cs index bfe6000..fb69e05 100644 --- a/ContinuousTests/ContinuousTestRunner.cs +++ b/ContinuousTests/ContinuousTestRunner.cs @@ -30,7 +30,7 @@ namespace ContinuousTests ClearAllCustomNamespaces(allTests, overviewLog); - var testLoops = allTests.Select(t => new TestLoop(taskFactory, config, overviewLog, t.GetType(), t.RunTestEvery, cancelToken)).ToArray(); + var testLoops = allTests.Select(t => new TestLoop(taskFactory, config, overviewLog, t.GetType(), t.RunTestEvery, startupChecker, cancelToken)).ToArray(); foreach (var testLoop in testLoops) { diff --git a/ContinuousTests/SingleTestRun.cs b/ContinuousTests/SingleTestRun.cs index 9115fdf..4d9a041 100644 --- a/ContinuousTests/SingleTestRun.cs +++ b/ContinuousTests/SingleTestRun.cs @@ -25,7 +25,7 @@ namespace ContinuousTests private readonly string dataFolder; private static int failureCount = 0; - public SingleTestRun(TaskFactory taskFactory, Configuration config, BaseLog overviewLog, TestHandle handle, CancellationToken cancelToken) + public SingleTestRun(TaskFactory taskFactory, Configuration config, BaseLog overviewLog, TestHandle handle, StartupChecker startupChecker, CancellationToken cancelToken) { this.taskFactory = taskFactory; this.config = config; @@ -34,6 +34,7 @@ namespace ContinuousTests this.cancelToken = cancelToken; testName = handle.Test.GetType().Name; fixtureLog = new FixtureLog(new LogConfig(config.LogPath, true), DateTime.UtcNow, testName); + ApplyLogReplacements(fixtureLog, startupChecker); nodes = CreateRandomNodes(handle.Test.RequiredNumberOfNodes); dataFolder = config.DataPath + "-" + Guid.NewGuid(); @@ -87,6 +88,11 @@ namespace ContinuousTests } } + private void ApplyLogReplacements(FixtureLog fixtureLog, StartupChecker startupChecker) + { + foreach (var replacement in startupChecker.LogReplacements) fixtureLog.AddStringReplace(replacement.From, replacement.To); + } + private void RunTestMoments() { var earliestMoment = handle.GetEarliestMoment(); diff --git a/ContinuousTests/StartupChecker.cs b/ContinuousTests/StartupChecker.cs index 5986fa5..2fee5eb 100644 --- a/ContinuousTests/StartupChecker.cs +++ b/ContinuousTests/StartupChecker.cs @@ -15,6 +15,7 @@ namespace ContinuousTests { this.config = config; this.cancelToken = cancelToken; + LogReplacements = new List(); } public void Check() @@ -28,6 +29,8 @@ namespace ContinuousTests log.Log("All OK."); } + public List LogReplacements { get; } + private void PreflightCheck(Configuration config) { var tests = testFactory.CreateTests(); @@ -90,6 +93,7 @@ namespace ContinuousTests if (info == null || string.IsNullOrEmpty(info.id)) return false; log.Log($"Codex version: '{info.codex.version}' revision: '{info.codex.revision}'"); + LogReplacements.Add(new BaseLogStringReplacement(info.id, n.GetName())); } catch { diff --git a/ContinuousTests/TestLoop.cs b/ContinuousTests/TestLoop.cs index e57fee8..79ae999 100644 --- a/ContinuousTests/TestLoop.cs +++ b/ContinuousTests/TestLoop.cs @@ -9,16 +9,18 @@ namespace ContinuousTests private readonly BaseLog overviewLog; private readonly Type testType; private readonly TimeSpan runsEvery; + private readonly StartupChecker startupChecker; private readonly CancellationToken cancelToken; private readonly EventWaitHandle runFinishedHandle = new EventWaitHandle(true, EventResetMode.ManualReset); - public TestLoop(TaskFactory taskFactory, Configuration config, BaseLog overviewLog, Type testType, TimeSpan runsEvery, CancellationToken cancelToken) + public TestLoop(TaskFactory taskFactory, Configuration config, BaseLog overviewLog, Type testType, TimeSpan runsEvery, StartupChecker startupChecker, CancellationToken cancelToken) { this.taskFactory = taskFactory; this.config = config; this.overviewLog = overviewLog; this.testType = testType; this.runsEvery = runsEvery; + this.startupChecker = startupChecker; this.cancelToken = cancelToken; Name = testType.Name; } @@ -58,7 +60,7 @@ namespace ContinuousTests { var test = (ContinuousTest)Activator.CreateInstance(testType)!; var handle = new TestHandle(test); - var run = new SingleTestRun(taskFactory, config, overviewLog, handle, cancelToken); + var run = new SingleTestRun(taskFactory, config, overviewLog, handle, startupChecker, cancelToken); runFinishedHandle.Reset(); run.Run(runFinishedHandle); diff --git a/DistTestCore/Codex/CodexApiTypes.cs b/DistTestCore/Codex/CodexApiTypes.cs index 32bf353..5944b84 100644 --- a/DistTestCore/Codex/CodexApiTypes.cs +++ b/DistTestCore/Codex/CodexApiTypes.cs @@ -1,7 +1,4 @@ -using KubernetesWorkflow; -using Logging; -using Newtonsoft.Json; -using Utils; +using Newtonsoft.Json; namespace DistTestCore.Codex { diff --git a/Logging/BaseLog.cs b/Logging/BaseLog.cs index 1164d1b..d11ecc1 100644 --- a/Logging/BaseLog.cs +++ b/Logging/BaseLog.cs @@ -60,6 +60,7 @@ namespace Logging public virtual void AddStringReplace(string from, string to) { if (string.IsNullOrWhiteSpace(from)) return; + if (replacements.Any(r => r.From == from)) return; replacements.Add(new BaseLogStringReplacement(from, to)); } @@ -98,20 +99,20 @@ namespace Logging public class BaseLogStringReplacement { - private readonly string from; - private readonly string to; - public BaseLogStringReplacement(string from, string to) { - this.from = from; - this.to = to; + From = from; + To = to; if (string.IsNullOrEmpty(from) || string.IsNullOrEmpty(to) || from == to) throw new ArgumentException(); } + public string From { get; } + public string To { get; } + public string Apply(string msg) { - return msg.Replace(from, to); + return msg.Replace(From, To); } } }