2
0
mirror of synced 2025-01-12 01:24:23 +00:00

Fixes issue where occassionally a CID contains 'ERR' and fails the log assert.

This commit is contained in:
Ben 2024-12-04 15:57:49 +01:00
parent 770ba6dcdc
commit 3e2cad3c17
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
3 changed files with 31 additions and 33 deletions

View File

@ -6,6 +6,7 @@ namespace KubernetesWorkflow
{
string ContainerName { get; }
void IterateLines(Action<string> action);
void IterateLines(Action<string> 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<string> action, params string[] thatContain)
public void IterateLines(Action<string> 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<string> 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<string>();
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<string>();
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();
}

View File

@ -23,5 +23,21 @@ namespace DistTestCore
}
CollectionAssert.IsEmpty(errors);
}
public static void AssertLogDoesNotContainLinesStartingWith(this IDownloadedLog log, params string[] unexpectedStrings)
{
var errors = new List<string>();
log.IterateLines(line =>
{
foreach (var str in unexpectedStrings)
{
if (line.StartsWith(str))
{
errors.Add($"Found '{str}' at start of line '{line}'.");
}
}
});
CollectionAssert.IsEmpty(errors);
}
}
}

View File

@ -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)