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
6 changed files with 56 additions and 35 deletions

View file

@ -4,6 +4,7 @@ using Microsoft.Extensions.Primitives;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using ModelContextProtocol.Tests.Utils;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
@ -251,7 +252,7 @@ public class MapMcpStreamableHttpTests(ITestOutputHelper outputHelper) : MapMcpT
Assert.NotNull(serverInfo);
Assert.False(string.IsNullOrEmpty(resumedSessionId));
await serverTcs.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
await serverTcs.Task.WaitAsync(TestConstants.DefaultTimeout, TestContext.Current.CancellationToken);
await using var resumeTransport = new HttpClientTransport(new()
{

View file

@ -10,6 +10,7 @@ using ModelContextProtocol.AspNetCore.Tests.Utils;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using ModelContextProtocol.Tests.Utils;
namespace ModelContextProtocol.AspNetCore.Tests;
@ -279,7 +280,7 @@ public class ResumabilityIntegrationTests(ITestOutputHelper testOutputHelper) :
[Fact]
public async Task Client_CanResumeUnsolicitedMessageStream_AfterDisconnection()
{
var timeout = TimeSpan.FromSeconds(10);
var timeout = TestConstants.DefaultTimeout;
using var faultingStreamHandler = new FaultingStreamHandler()
{
InnerHandler = SocketsHttpHandler,

View file

@ -83,7 +83,7 @@ public class ServerConformanceTests : IAsyncLifetime
{
try
{
await _serverTask.WaitAsync(TimeSpan.FromSeconds(5));
await _serverTask.WaitAsync(TestConstants.DefaultTimeout);
}
catch
{

View file

@ -8,6 +8,7 @@ using ModelContextProtocol.AspNetCore.Tests.Utils;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using ModelContextProtocol.Tests.Utils;
using System.Text.Json.Serialization;
using TestServerWithHosting.Tools;
@ -110,7 +111,7 @@ public partial class SseIntegrationTests(ITestOutputHelper outputHelper) : Kestr
// Send a test message through POST endpoint
await mcpClient.SendNotificationAsync("test/notification", new Envelope { Message = "Hello from client!" }, serializerOptions: JsonContext.Default.Options, cancellationToken: TestContext.Current.CancellationToken);
var message = await receivedNotification.Task.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
var message = await receivedNotification.Task.WaitAsync(TestConstants.DefaultTimeout, TestContext.Current.CancellationToken);
Assert.Equal("Hello from server!", message);
}

View file

@ -6,6 +6,7 @@ using ModelContextProtocol.AspNetCore.Tests.Utils;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using ModelContextProtocol.Tests.Utils;
using System.Threading;
using System.Threading.Tasks;
using System.Text.Json;
@ -245,7 +246,7 @@ public class StreamableHttpClientConformanceTests(ITestOutputHelper outputHelper
loggerFactory: LoggerFactory,
cancellationToken: TestContext.Current.CancellationToken))
{
var observedSessionId = await resumeServer.GetStarted.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
var observedSessionId = await resumeServer.GetStarted.WaitAsync(TestConstants.DefaultTimeout, TestContext.Current.CancellationToken);
Assert.Equal(sessionId, observedSessionId);
var tools = await client.ListToolsAsync(cancellationToken: TestContext.Current.CancellationToken);

View file

@ -249,7 +249,7 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
await Task.WhenAll(echoTasks);
}
[Fact]
[Fact(Skip = "https://github.com/modelcontextprotocol/csharp-sdk/issues/1211")]
public async Task GetRequest_Receives_UnsolicitedNotifications()
{
McpServer? server = null;