Fix HandlesIProgressParameter test sporadically failing in CI (#327)

This commit is contained in:
Stephen Toub 2025-04-18 12:23:19 -04:00 • committed by GitHub
commit d65ddce268
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -596,11 +596,22 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
McpClientTool progressTool = tools.First(t => t.Name == nameof(EchoTool.SendsProgressNotifications));
TaskCompletionSource tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
int remainingNotifications = 10;
ConcurrentQueue<ProgressNotification> notifications = new();
await using (client.RegisterNotificationHandler(NotificationMethods.ProgressNotification, (notification, cancellationToken) =>
{
ProgressNotification pn = JsonSerializer.Deserialize<ProgressNotification>(notification.Params, McpJsonUtilities.DefaultOptions)!;
notifications.Enqueue(pn);
if (JsonSerializer.Deserialize<ProgressNotification>(notification.Params, McpJsonUtilities.DefaultOptions) is { } pn &&
pn.ProgressToken == new ProgressToken("abc123"))
{
notifications.Enqueue(pn);
if (Interlocked.Decrement(ref remainingNotifications) == 0)
{
tcs.SetResult();
}
}
return default;
}))
{
@ -613,8 +624,8 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
},
cancellationToken: TestContext.Current.CancellationToken);
await tcs.Task;
Assert.Contains("done", JsonSerializer.Serialize(result, McpJsonUtilities.DefaultOptions));
SpinWait.SpinUntil(() => notifications.Count == 10, TimeSpan.FromSeconds(10));
}
ProgressNotification[] array = notifications.OrderBy(n => n.Progress.Progress).ToArray();