Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden LogFormatSpec #7429

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strip the offending [DEBUG][DateTime][Thread 0001][EventStream(test)] Logger log1-TestEventListener [Akka.TestKit.TestEventListener] line if the TestEventListener is detected.

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
Loading