Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions tests/ModelContextProtocol.Tests/DiagnosticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ await RunConnected(async (client, server) =>

// 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);
Expand Down Expand Up @@ -103,8 +105,11 @@ await RunConnected(async (client, server) =>
await Assert.ThrowsAsync<McpProtocolException>(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);
Expand Down Expand Up @@ -173,8 +178,10 @@ await RunConnected(async (client, server) =>
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
Expand Down