Skip to content
Closed
Changes from 2 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
12 changes: 12 additions & 0 deletions tests/ModelContextProtocol.Tests/DiagnosticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class DiagnosticTests
[Fact]
public async Task Session_TracksActivities()
{
// Ensure no ambient activity from previous tests
Activity.Current = null;
Comment thread
stephentoub marked this conversation as resolved.
Outdated

var activities = new List<Activity>();
var clientToServerLog = new List<string>();

Expand All @@ -32,6 +35,9 @@ await RunConnected(async (client, server) =>
var tool = tools.First(t => t.Name == "DoubleValue");
await tool.InvokeAsync(new() { ["amount"] = 42 }, TestContext.Current.CancellationToken);
}, clientToServerLog);

// Ensure all activities are flushed before disposal
tracerProvider.ForceFlush();
}

Assert.NotEmpty(activities);
Expand Down Expand Up @@ -77,6 +83,9 @@ await RunConnected(async (client, server) =>
[Fact]
public async Task Session_FailedToolCall()
{
// Ensure no ambient activity from previous tests
Activity.Current = null;

var activities = new List<Activity>();

using (var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
Expand All @@ -89,6 +98,9 @@ await RunConnected(async (client, server) =>
await client.CallToolAsync("Throw", cancellationToken: TestContext.Current.CancellationToken);
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.CallToolAsync("does-not-exist", cancellationToken: TestContext.Current.CancellationToken));
}, []);

// Ensure all activities are flushed before disposal
tracerProvider.ForceFlush();
}

Assert.NotEmpty(activities);
Expand Down