From c094707c3760b319a94aea21d25b17d3dbb7fbfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81api=C5=84ski?= Date: Sat, 28 Nov 2026 12:16:34 +0100 Subject: [PATCH] test: wait for the request spans before reading errors On .NET 11 the request span is named after its route only when it ends, which can be after the test server has answered. --- .../Integration/ErrorApiTests.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/MonitorWay.Tests/Integration/ErrorApiTests.cs b/src/MonitorWay.Tests/Integration/ErrorApiTests.cs index 32ee362..b63203a 100644 --- a/src/MonitorWay.Tests/Integration/ErrorApiTests.cs +++ b/src/MonitorWay.Tests/Integration/ErrorApiTests.cs @@ -32,9 +32,22 @@ public async Task ExceptionLoggedAndRecordedOnItsSpan_IsOneOccurrence() await client.GetAsync("/pay"); await client.GetAsync("/pay"); - app.Services.GetRequiredService().Tick(); - var page = await PostAsync(app, "GetErrors", new { query = new { text = "type:Timeout" } }); + // The test server answers before the request's span ends, and on .NET 11 the span is named after its route only + // then, so the traces are read once both requests have been joined to their spans. + var store = app.Services.GetRequiredService(); + ErrorsPageDto page; + var deadline = DateTime.UtcNow.AddSeconds(5); + do + { + store.Tick(); + page = await PostAsync(app, "GetErrors", new { query = new { text = "type:Timeout" } }); + if (page.Errors is [{ Endpoints: ["GET /pay"] }]) + break; + await Task.Delay(20); + } + while (DateTime.UtcNow < deadline); + var row = Assert.Single(page.Errors); Assert.Equal("System.TimeoutException", row.Type); Assert.Equal(2, row.Count);