From 3e2cad3c171b4df17df883bc66f624352bcacd86 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 4 Dec 2024 15:57:49 +0100 Subject: [PATCH] Fixes issue where occassionally a CID contains 'ERR' and fails the log assert. --- Framework/KubernetesWorkflow/DownloadedLog.cs | 46 ++++++------------- Tests/DistTestCore/DownloadedLogExtensions.cs | 16 +++++++ Tests/ExperimentalTests/CodexDistTest.cs | 2 +- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Framework/KubernetesWorkflow/DownloadedLog.cs b/Framework/KubernetesWorkflow/DownloadedLog.cs index a3f0809..edc6207 100644 --- a/Framework/KubernetesWorkflow/DownloadedLog.cs +++ b/Framework/KubernetesWorkflow/DownloadedLog.cs @@ -6,6 +6,7 @@ namespace KubernetesWorkflow { string ContainerName { get; } + void IterateLines(Action action); void IterateLines(Action action, params string[] thatContain); string[] GetLinesContaining(string expectedString); string[] FindLinesThatContain(params string[] tags); @@ -25,58 +26,39 @@ namespace KubernetesWorkflow public string ContainerName { get; } - public void IterateLines(Action action, params string[] thatContain) + public void IterateLines(Action action) { using var file = File.OpenRead(logFile.FullFilename); using var streamReader = new StreamReader(file); var line = streamReader.ReadLine(); while (line != null) + { + action(line); + line = streamReader.ReadLine(); + } + } + + public void IterateLines(Action action, params string[] thatContain) + { + IterateLines(line => { if (thatContain.All(line.Contains)) { action(line); } - line = streamReader.ReadLine(); - } + }); } public string[] GetLinesContaining(string expectedString) { - using var file = File.OpenRead(logFile.FullFilename); - using var streamReader = new StreamReader(file); - var lines = new List(); - - var line = streamReader.ReadLine(); - while (line != null) - { - if (line.Contains(expectedString)) - { - lines.Add(line); - } - line = streamReader.ReadLine(); - } - - return lines.ToArray(); ; + return FindLinesThatContain([expectedString]); } public string[] FindLinesThatContain(params string[] tags) { var result = new List(); - using var file = File.OpenRead(logFile.FullFilename); - using var streamReader = new StreamReader(file); - - var line = streamReader.ReadLine(); - while (line != null) - { - if (tags.All(line.Contains)) - { - result.Add(line); - } - - line = streamReader.ReadLine(); - } - + IterateLines(result.Add, tags); return result.ToArray(); } diff --git a/Tests/DistTestCore/DownloadedLogExtensions.cs b/Tests/DistTestCore/DownloadedLogExtensions.cs index 91eeb08..3d4cb84 100644 --- a/Tests/DistTestCore/DownloadedLogExtensions.cs +++ b/Tests/DistTestCore/DownloadedLogExtensions.cs @@ -23,5 +23,21 @@ namespace DistTestCore } CollectionAssert.IsEmpty(errors); } + + public static void AssertLogDoesNotContainLinesStartingWith(this IDownloadedLog log, params string[] unexpectedStrings) + { + var errors = new List(); + log.IterateLines(line => + { + foreach (var str in unexpectedStrings) + { + if (line.StartsWith(str)) + { + errors.Add($"Found '{str}' at start of line '{line}'."); + } + } + }); + CollectionAssert.IsEmpty(errors); + } } } diff --git a/Tests/ExperimentalTests/CodexDistTest.cs b/Tests/ExperimentalTests/CodexDistTest.cs index d8f75e8..13365bf 100644 --- a/Tests/ExperimentalTests/CodexDistTest.cs +++ b/Tests/ExperimentalTests/CodexDistTest.cs @@ -99,7 +99,7 @@ namespace CodexTests var log = Ci.DownloadLog(node); log.AssertLogDoesNotContain("Block validation failed"); - log.AssertLogDoesNotContain("ERR "); + log.AssertLogDoesNotContainLinesStartingWith("ERR "); } public void LogNodeStatus(ICodexNode node, IMetricsAccess? metrics = null)