Fix HandlesIProgressParameter test sporadically failing in CI (#327)
This commit is contained in:
parent
b0cd6541ce
commit
d65ddce268
1 changed files with 14 additions and 3 deletions
|
|
@ -596,11 +596,22 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
|
||||||
|
|
||||||
McpClientTool progressTool = tools.First(t => t.Name == nameof(EchoTool.SendsProgressNotifications));
|
McpClientTool progressTool = tools.First(t => t.Name == nameof(EchoTool.SendsProgressNotifications));
|
||||||
|
|
||||||
|
TaskCompletionSource tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
int remainingNotifications = 10;
|
||||||
|
|
||||||
ConcurrentQueue<ProgressNotification> notifications = new();
|
ConcurrentQueue<ProgressNotification> notifications = new();
|
||||||
await using (client.RegisterNotificationHandler(NotificationMethods.ProgressNotification, (notification, cancellationToken) =>
|
await using (client.RegisterNotificationHandler(NotificationMethods.ProgressNotification, (notification, cancellationToken) =>
|
||||||
{
|
{
|
||||||
ProgressNotification pn = JsonSerializer.Deserialize<ProgressNotification>(notification.Params, McpJsonUtilities.DefaultOptions)!;
|
if (JsonSerializer.Deserialize<ProgressNotification>(notification.Params, McpJsonUtilities.DefaultOptions) is { } pn &&
|
||||||
notifications.Enqueue(pn);
|
pn.ProgressToken == new ProgressToken("abc123"))
|
||||||
|
{
|
||||||
|
notifications.Enqueue(pn);
|
||||||
|
if (Interlocked.Decrement(ref remainingNotifications) == 0)
|
||||||
|
{
|
||||||
|
tcs.SetResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
|
|
@ -613,8 +624,8 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
|
||||||
},
|
},
|
||||||
cancellationToken: TestContext.Current.CancellationToken);
|
cancellationToken: TestContext.Current.CancellationToken);
|
||||||
|
|
||||||
|
await tcs.Task;
|
||||||
Assert.Contains("done", JsonSerializer.Serialize(result, McpJsonUtilities.DefaultOptions));
|
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();
|
ProgressNotification[] array = notifications.OrderBy(n => n.Progress.Progress).ToArray();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue