Skip to content

Commit

Permalink
Harden LogFormatSpec (#7429)
Browse files Browse the repository at this point in the history
close #7421
  • Loading branch information
Aaronontheweb authored Dec 20, 2024
1 parent f2ec912 commit 61bdebf
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/core/Akka.API.Tests/LogFormatSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,28 @@ await AwaitConditionAsync(() =>
// need to sanitize the thread id
text = SanitizeDateTime(text);
text = SanitizeThreadNumber(text);
// to resolve https://github.com/akkadotnet/akka.net/issues/7421
text = SanitizeTestEventListener(text);

await Verifier.Verify(text);
}

private static string SanitizeTestEventListener(string logs)
{
var pattern = @"^.*Akka\.TestKit\.TestEventListener.*$";
var result = Regex.Replace(logs, pattern, string.Empty, RegexOptions.Multiline);
return result;
}

static string SanitizeThreadNumber(string log)
private static string SanitizeThreadNumber(string log)
{
string pattern = @"(\[Thread )\d+(\])";
string replacement = "[Thread 0001]";
string result = Regex.Replace(log, pattern, replacement);
var pattern = @"(\[Thread )\d+(\])";
var replacement = "[Thread 0001]";
var result = Regex.Replace(log, pattern, replacement);
return result;
}

static string SanitizeDateTime(string logs, string replacement = "DateTime")
private static string SanitizeDateTime(string logs, string replacement = "DateTime")
{
// Regular expression to match the datetime
string pattern = @"\[\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}\.\d{3}Z\]";
Expand Down

0 comments on commit 61bdebf

Please sign in to comment.