Centralize test timeout constants to fix sporadic CI failures (#1210)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
Co-authored-by: Eric StJohn <ericstj@microsoft.com>
This commit is contained in:
Copilot 2026-01-29 22:06:17 -05:00 • committed by GitHub
commit 8e57ac6b0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using ModelContextProtocol.Tests.Utils;
using System.Text.Json;
namespace ModelContextProtocol.Tests.Server;
@ -77,10 +78,10 @@ public class TaskCancellationIntegrationTests : ClientServerTestBase
Assert.NotNull(callResult.Task);
// Wait for the tool to start executing
await _toolStarted.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
await _toolStarted.Task.WaitAsync(TestConstants.DefaultTimeout, TestContext.Current.CancellationToken);
// Assert - Wait for the cancellation to fire (should happen when TTL expires)
var cancelled = await _toolCancellationFired.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
var cancelled = await _toolCancellationFired.Task.WaitAsync(TestConstants.DefaultTimeout, TestContext.Current.CancellationToken);
Assert.True(cancelled, "Tool's CancellationToken should have been triggered when TTL expired");
// Note: TTL-based expiration does not explicitly set task status to Cancelled.
@ -108,13 +109,13 @@ public class TaskCancellationIntegrationTests : ClientServerTestBase
string taskId = callResult.Task.TaskId;
// Wait for the tool to start executing
await _toolStarted.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
await _toolStarted.Task.WaitAsync(TestConstants.DefaultTimeout, TestContext.Current.CancellationToken);
// Act - Explicitly cancel the task
var cancelledTask = await client.CancelTaskAsync(taskId, cancellationToken: TestContext.Current.CancellationToken);
// Assert - Wait for the cancellation to propagate to the tool
var cancelled = await _toolCancellationFired.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
var cancelled = await _toolCancellationFired.Task.WaitAsync(TestConstants.DefaultTimeout, TestContext.Current.CancellationToken);
Assert.True(cancelled, "Tool's CancellationToken should have been triggered by explicit cancellation");
// Verify task status
@ -255,7 +256,7 @@ public class TaskCancellationConcurrencyTests : ClientServerTestBase
{
lock (_lock)
{
return _toolStarts[marker].Task.WaitAsync(TimeSpan.FromSeconds(5), ct);
return _toolStarts[marker].Task.WaitAsync(TestConstants.DefaultTimeout, ct);
}
}
@ -263,7 +264,7 @@ public class TaskCancellationConcurrencyTests : ClientServerTestBase
{
lock (_lock)
{
return _toolCancellations[marker].Task.WaitAsync(TimeSpan.FromSeconds(5), ct);
return _toolCancellations[marker].Task.WaitAsync(TestConstants.DefaultTimeout, ct);
}
}