From d9ae6bc266e27061a1c186ac8d70d020dd4f7939 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Feb 2026 19:42:45 -0800 Subject: [PATCH] Fix flaky DiagnosticTests on net10.0 by waiting for specific activities (#1324) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../DiagnosticTests.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/ModelContextProtocol.Tests/DiagnosticTests.cs b/tests/ModelContextProtocol.Tests/DiagnosticTests.cs index a3d9b4e..2ae0fea 100644 --- a/tests/ModelContextProtocol.Tests/DiagnosticTests.cs +++ b/tests/ModelContextProtocol.Tests/DiagnosticTests.cs @@ -35,8 +35,10 @@ public class DiagnosticTests // Wait for server-side activities to be exported. The server processes messages // via fire-and-forget tasks, so activities may not be immediately available - // after the client operation completes. - await WaitForAsync(() => activities.Count(a => a.Kind == ActivityKind.Server) >= 4); + // after the client operation completes. Wait for the specific activity we need + // rather than a count, as other server activities may be exported first. + await WaitForAsync(() => activities.Any(a => + a.DisplayName == "tools/call DoubleValue" && a.Kind == ActivityKind.Server)); } Assert.NotEmpty(activities); @@ -103,8 +105,11 @@ public class DiagnosticTests await Assert.ThrowsAsync(async () => await client.CallToolAsync("does-not-exist", cancellationToken: TestContext.Current.CancellationToken)); }, []); - // Wait for server-side activities to be exported. - await WaitForAsync(() => activities.Count(a => a.Kind == ActivityKind.Server) >= 4); + // Wait for server-side activities to be exported. Wait for specific activities + // rather than a count, as other server activities may be exported first. + await WaitForAsync(() => + activities.Any(a => a.DisplayName == "tools/call Throw" && a.Kind == ActivityKind.Server) && + activities.Any(a => a.DisplayName == "tools/call does-not-exist" && a.Kind == ActivityKind.Server)); } Assert.NotEmpty(activities); @@ -173,8 +178,10 @@ public class DiagnosticTests await tool.InvokeAsync(new() { ["amount"] = 42 }, TestContext.Current.CancellationToken); }, []); - // Wait for server-side activities to be exported. - await WaitForAsync(() => activities.Count(a => a.Kind == ActivityKind.Server) >= 3); + // Wait for server-side activities to be exported. Wait for specific activities + // rather than a count, as other server activities may be exported first. + await WaitForAsync(() => activities.Any(a => + a.DisplayName == "tools/call DoubleValue" && a.Kind == ActivityKind.Server)); } // The outer activity should have MCP-specific attributes added to it