Skip to content

Commit 3e2cad3

Browse files
committed
Fixes issue where occassionally a CID contains 'ERR' and fails the log assert.
1 parent 770ba6d commit 3e2cad3

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

Framework/KubernetesWorkflow/DownloadedLog.cs

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public interface IDownloadedLog
66
{
77
string ContainerName { get; }
88

9+
void IterateLines(Action<string> action);
910
void IterateLines(Action<string> action, params string[] thatContain);
1011
string[] GetLinesContaining(string expectedString);
1112
string[] FindLinesThatContain(params string[] tags);
@@ -25,58 +26,39 @@ internal DownloadedLog(WriteToFileLogHandler logHandler, string containerName)
2526

2627
public string ContainerName { get; }
2728

28-
public void IterateLines(Action<string> action, params string[] thatContain)
29+
public void IterateLines(Action<string> action)
2930
{
3031
using var file = File.OpenRead(logFile.FullFilename);
3132
using var streamReader = new StreamReader(file);
3233

3334
var line = streamReader.ReadLine();
3435
while (line != null)
3536
{
36-
if (thatContain.All(line.Contains))
37-
{
38-
action(line);
39-
}
37+
action(line);
4038
line = streamReader.ReadLine();
4139
}
4240
}
4341

44-
public string[] GetLinesContaining(string expectedString)
42+
public void IterateLines(Action<string> action, params string[] thatContain)
4543
{
46-
using var file = File.OpenRead(logFile.FullFilename);
47-
using var streamReader = new StreamReader(file);
48-
var lines = new List<string>();
49-
50-
var line = streamReader.ReadLine();
51-
while (line != null)
44+
IterateLines(line =>
5245
{
53-
if (line.Contains(expectedString))
46+
if (thatContain.All(line.Contains))
5447
{
55-
lines.Add(line);
48+
action(line);
5649
}
57-
line = streamReader.ReadLine();
58-
}
50+
});
51+
}
5952

60-
return lines.ToArray(); ;
53+
public string[] GetLinesContaining(string expectedString)
54+
{
55+
return FindLinesThatContain([expectedString]);
6156
}
6257

6358
public string[] FindLinesThatContain(params string[] tags)
6459
{
6560
var result = new List<string>();
66-
using var file = File.OpenRead(logFile.FullFilename);
67-
using var streamReader = new StreamReader(file);
68-
69-
var line = streamReader.ReadLine();
70-
while (line != null)
71-
{
72-
if (tags.All(line.Contains))
73-
{
74-
result.Add(line);
75-
}
76-
77-
line = streamReader.ReadLine();
78-
}
79-
61+
IterateLines(result.Add, tags);
8062
return result.ToArray();
8163
}
8264

Tests/DistTestCore/DownloadedLogExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,21 @@ public static void AssertLogDoesNotContain(this IDownloadedLog log, params strin
2323
}
2424
CollectionAssert.IsEmpty(errors);
2525
}
26+
27+
public static void AssertLogDoesNotContainLinesStartingWith(this IDownloadedLog log, params string[] unexpectedStrings)
28+
{
29+
var errors = new List<string>();
30+
log.IterateLines(line =>
31+
{
32+
foreach (var str in unexpectedStrings)
33+
{
34+
if (line.StartsWith(str))
35+
{
36+
errors.Add($"Found '{str}' at start of line '{line}'.");
37+
}
38+
}
39+
});
40+
CollectionAssert.IsEmpty(errors);
41+
}
2642
}
2743
}

Tests/ExperimentalTests/CodexDistTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void CheckLogForErrors(ICodexNode node)
9999
var log = Ci.DownloadLog(node);
100100

101101
log.AssertLogDoesNotContain("Block validation failed");
102-
log.AssertLogDoesNotContain("ERR ");
102+
log.AssertLogDoesNotContainLinesStartingWith("ERR ");
103103
}
104104

105105
public void LogNodeStatus(ICodexNode node, IMetricsAccess? metrics = null)

0 commit comments

Comments
 (0)