mirror of
https://github.com/DuendeSoftware/products
synced 2026-05-24 01:18:22 +00:00
add retries for the flakey FrontendCountDiagnosticEntryTests
This commit is contained in:
parent
5c5296ec08
commit
8752ab5b44
2 changed files with 25 additions and 8 deletions
|
|
@ -21,10 +21,7 @@ public class FrontendCountDiagnosticEntryTests(ITestOutputHelper testOutputHelpe
|
|||
|
||||
AdvanceClock(TimeSpan.FromHours(1));
|
||||
|
||||
await Task.Delay(100);
|
||||
|
||||
var bffLogMessages = Context.LogMessages.ToString().Split(Environment.NewLine).Where(x => x.StartsWith("bff"));
|
||||
bffLogMessages.ShouldContain(x => x.Contains("\"FrontendCount\":0"));
|
||||
await WaitForLogMessage("\"FrontendCount\":0");
|
||||
|
||||
AddOrUpdateFrontend(new BffFrontend
|
||||
{
|
||||
|
|
@ -37,9 +34,6 @@ public class FrontendCountDiagnosticEntryTests(ITestOutputHelper testOutputHelpe
|
|||
|
||||
AdvanceClock(TimeSpan.FromHours(1));
|
||||
|
||||
await Task.Delay(100);
|
||||
|
||||
bffLogMessages = Context.LogMessages.ToString().Split(Environment.NewLine).Where(x => x.StartsWith("bff"));
|
||||
bffLogMessages.ShouldContain(x => x.Contains("\"FrontendCount\":2"));
|
||||
await WaitForLogMessage("\"FrontendCount\":2");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,5 +252,28 @@ public abstract class BffTestBase : IAsyncDisposable
|
|||
};
|
||||
|
||||
protected void AdvanceClock(TimeSpan by) => The.Clock.SetUtcNow(The.Clock.GetUtcNow().Add(by));
|
||||
|
||||
protected async Task WaitForLogMessage(string expected, int maxRetries = 20, int delayMs = 100)
|
||||
{
|
||||
for (var i = 0; i < maxRetries; i++)
|
||||
{
|
||||
var bffLogMessages = Context.LogMessages.ToString()
|
||||
.Split(Environment.NewLine)
|
||||
.Where(x => x.StartsWith("bff"));
|
||||
|
||||
if (bffLogMessages.Any(x => x.Contains(expected)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Task.Delay(delayMs);
|
||||
}
|
||||
|
||||
// Final assertion to produce a clear failure message
|
||||
var finalMessages = Context.LogMessages.ToString()
|
||||
.Split(Environment.NewLine)
|
||||
.Where(x => x.StartsWith("bff"));
|
||||
finalMessages.ShouldContain(x => x.Contains(expected));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue