Skip to content

Commit d9ae6bc

Browse files
Copilotstephentoub
andauthored
Fix flaky DiagnosticTests on net10.0 by waiting for specific activities (#1324)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: stephentoub <[email protected]>
1 parent 49141a3 commit d9ae6bc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/ModelContextProtocol.Tests/DiagnosticTests.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ await RunConnected(async (client, server) =>
3535

3636
// Wait for server-side activities to be exported. The server processes messages
3737
// via fire-and-forget tasks, so activities may not be immediately available
38-
// after the client operation completes.
39-
await WaitForAsync(() => activities.Count(a => a.Kind == ActivityKind.Server) >= 4);
38+
// after the client operation completes. Wait for the specific activity we need
39+
// rather than a count, as other server activities may be exported first.
40+
await WaitForAsync(() => activities.Any(a =>
41+
a.DisplayName == "tools/call DoubleValue" && a.Kind == ActivityKind.Server));
4042
}
4143

4244
Assert.NotEmpty(activities);
@@ -103,8 +105,11 @@ await RunConnected(async (client, server) =>
103105
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.CallToolAsync("does-not-exist", cancellationToken: TestContext.Current.CancellationToken));
104106
}, []);
105107

106-
// Wait for server-side activities to be exported.
107-
await WaitForAsync(() => activities.Count(a => a.Kind == ActivityKind.Server) >= 4);
108+
// Wait for server-side activities to be exported. Wait for specific activities
109+
// rather than a count, as other server activities may be exported first.
110+
await WaitForAsync(() =>
111+
activities.Any(a => a.DisplayName == "tools/call Throw" && a.Kind == ActivityKind.Server) &&
112+
activities.Any(a => a.DisplayName == "tools/call does-not-exist" && a.Kind == ActivityKind.Server));
108113
}
109114

110115
Assert.NotEmpty(activities);
@@ -173,8 +178,10 @@ await RunConnected(async (client, server) =>
173178
await tool.InvokeAsync(new() { ["amount"] = 42 }, TestContext.Current.CancellationToken);
174179
}, []);
175180

176-
// Wait for server-side activities to be exported.
177-
await WaitForAsync(() => activities.Count(a => a.Kind == ActivityKind.Server) >= 3);
181+
// Wait for server-side activities to be exported. Wait for specific activities
182+
// rather than a count, as other server activities may be exported first.
183+
await WaitForAsync(() => activities.Any(a =>
184+
a.DisplayName == "tools/call DoubleValue" && a.Kind == ActivityKind.Server));
178185
}
179186

180187
// The outer activity should have MCP-specific attributes added to it

0 commit comments

Comments
 (0)