From 61bdebf6b9d24f858a2aa42263fe08e4ed62784d Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Fri, 20 Dec 2024 14:13:48 -0600 Subject: [PATCH] Harden `LogFormatSpec` (#7429) close #7421 --- src/core/Akka.API.Tests/LogFormatSpec.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/Akka.API.Tests/LogFormatSpec.cs b/src/core/Akka.API.Tests/LogFormatSpec.cs index b778b8114b9..ccba7946a3e 100644 --- a/src/core/Akka.API.Tests/LogFormatSpec.cs +++ b/src/core/Akka.API.Tests/LogFormatSpec.cs @@ -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\]";