Skip to content

Commit 17867ee

Browse files
committed
Add shorter timeout on Client_CanResumeUnsolicitedMessageStream_AfterDisconnection
1 parent 66083ea commit 17867ee

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tests/ModelContextProtocol.AspNetCore.Tests/ResumabilityIntegrationTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public async Task Client_CanResumePostResponseStream_AfterDisconnection()
279279
[Fact]
280280
public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
281281
{
282+
var timeout = TimeSpan.FromSeconds(10);
282283
using var faultingStreamHandler = new FaultingStreamHandler()
283284
{
284285
InnerHandler = SocketsHttpHandler,
@@ -304,12 +305,12 @@ public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
304305
await using var client = await ConnectClientAsync();
305306

306307
// Get the server instance
307-
var server = await serverTcs.Task.WaitAsync(TestContext.Current.CancellationToken);
308+
var server = await serverTcs.Task.WaitAsync(timeout, TestContext.Current.CancellationToken);
308309

309310
// Set up notification tracking with unique messages
310-
var clientReceivedInitialNotificationTcs = new TaskCompletionSource();
311-
var clientReceivedReplayedNotificationTcs = new TaskCompletionSource();
312-
var clientReceivedReconnectNotificationTcs = new TaskCompletionSource();
311+
var clientReceivedInitialNotificationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
312+
var clientReceivedReplayedNotificationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
313+
var clientReceivedReconnectNotificationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
313314

314315
const string CustomNotificationMethod = "test/custom_notification";
315316
const string InitialMessage = "Initial notification";
@@ -347,7 +348,7 @@ public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
347348
await server.SendNotificationAsync(CustomNotificationMethod, new JsonObject { ["message"] = InitialMessage }, cancellationToken: TestContext.Current.CancellationToken);
348349

349350
// Wait for client to receive the first notification
350-
await clientReceivedInitialNotificationTcs.Task.WaitAsync(TestContext.Current.CancellationToken);
351+
await clientReceivedInitialNotificationTcs.Task.WaitAsync(timeout, TestContext.Current.CancellationToken);
351352

352353
// Fault the unsolicited message stream (GET SSE)
353354
var reconnectAttempt = await faultingStreamHandler.TriggerFaultAsync(TestContext.Current.CancellationToken);
@@ -359,13 +360,13 @@ public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
359360
reconnectAttempt.Continue();
360361

361362
// Wait for client to receive the notification via replay
362-
await clientReceivedReplayedNotificationTcs.Task.WaitAsync(TestContext.Current.CancellationToken);
363+
await clientReceivedReplayedNotificationTcs.Task.WaitAsync(timeout, TestContext.Current.CancellationToken);
363364

364365
// Send a final notification while the client has reconnected - this should be handled by the transport
365366
await server.SendNotificationAsync(CustomNotificationMethod, new JsonObject { ["message"] = ReconnectMessage }, cancellationToken: TestContext.Current.CancellationToken);
366367

367368
// Wait for the client to receive the final notification
368-
await clientReceivedReconnectNotificationTcs.Task.WaitAsync(TestContext.Current.CancellationToken);
369+
await clientReceivedReconnectNotificationTcs.Task.WaitAsync(timeout, TestContext.Current.CancellationToken);
369370

370371
// Assert each notification was received exactly once
371372
Assert.Equal(1, initialNotificationReceivedCount);

0 commit comments

Comments
 (0)