Skip to content

Commit 7427d11

Browse files
jeffhandleyCopilot
andcommitted
Use generic TaskCompletionSource<bool> in batched change-notification tests
The non-generic TaskCompletionSource is .NET 5+ only and fails to compile under net472, which ModelContextProtocol.Tests targets. Switch to the generic form in the DeferChangedEvents batch tests for tools, prompts, and resources: new TaskCompletionSource() becomes new TaskCompletionSource<bool>() and TrySetResult() becomes TrySetResult(true). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e6c8744 commit 7427d11

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsPromptsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ public async Task DeferChangedEvents_BatchAddPrompts_EmitsExactlyOneNotification
188188
Assert.NotNull(serverPrompts);
189189

190190
int notificationCount = 0;
191-
var firstNotification = new TaskCompletionSource();
191+
var firstNotification = new TaskCompletionSource<bool>();
192192

193193
await using (client.RegisterNotificationHandler(NotificationMethods.PromptListChangedNotification, (notification, cancellationToken) =>
194194
{
195195
if (Interlocked.Increment(ref notificationCount) == 1)
196196
{
197-
firstNotification.TrySetResult();
197+
firstNotification.TrySetResult(true);
198198
}
199199
return default;
200200
}))

tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsResourcesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ public async Task DeferChangedEvents_BatchAddResources_EmitsExactlyOneNotificati
222222
Assert.NotNull(serverResources);
223223

224224
int notificationCount = 0;
225-
var firstNotification = new TaskCompletionSource();
225+
var firstNotification = new TaskCompletionSource<bool>();
226226

227227
await using (client.RegisterNotificationHandler(NotificationMethods.ResourceListChangedNotification, (notification, cancellationToken) =>
228228
{
229229
if (Interlocked.Increment(ref notificationCount) == 1)
230230
{
231-
firstNotification.TrySetResult();
231+
firstNotification.TrySetResult(true);
232232
}
233233
return default;
234234
}))

tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ public async Task DeferChangedEvents_BatchAddTools_EmitsExactlyOneNotification()
247247
Assert.NotNull(serverTools);
248248

249249
int notificationCount = 0;
250-
var firstNotification = new TaskCompletionSource();
250+
var firstNotification = new TaskCompletionSource<bool>();
251251

252252
await using (client.RegisterNotificationHandler(NotificationMethods.ToolListChangedNotification, (notification, cancellationToken) =>
253253
{
254254
if (Interlocked.Increment(ref notificationCount) == 1)
255255
{
256-
firstNotification.TrySetResult();
256+
firstNotification.TrySetResult(true);
257257
}
258258
return default;
259259
}))

0 commit comments

Comments
 (0)