Centralize test timeout constants to fix CI flakiness#1224
Conversation
- Add HttpClientTimeout and HttpClientHealthCheckTimeout constants to TestConstants - Update all HttpClient.Timeout usages in tests to use centralized constants - Update all WaitForExitAsync calls to use TestConstants.DefaultTimeout - Update HttpClientTransportOptions.ConnectionTimeout default from 30s to 60s to match test timeout - Ensure consistent timeout behavior across tests to prevent CI timeouts Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
src/ModelContextProtocol.Core/Client/HttpClientTransportOptions.cs
Outdated
Show resolved
Hide resolved
- Revert HttpClientTransportOptions.ConnectionTimeout from 60s back to 30s (no product changes) - Rename HttpClientHealthCheckTimeout to HttpClientPollingTimeout per feedback - Update all usages of the renamed constant - HttpClientTransportTests.cs does not need changes (uses test-specific ConnectionTimeout for mock handlers) Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com>
Addressed all feedback in commit 6d5b204. Regarding |
|
Working on the same issue locally in copilot CLI it also came up with a fix to test service to wait for the service to start. |
SummaryThe issue was a race condition in the OAuth test setup. The TestOAuthServer was started asynchronously in the OAuthTestBase constructor without waiting for it to be fully ready to accept connections. In CI environments with higher load, the OAuth server may take Root CauseThe test infrastructure in OAuthTestBase started the OAuth server with: _testOAuthRunTask = TestOAuthServer.RunServerAsync(cancellationToken: TestCts.Token);This task was never awaited before tests began making requests. Under CI load, if the server wasn't ready when the first OAuth metadata discovery requests were made, the HTTP client would wait until its timeout (10 seconds) was reached. Fix |
stephentoub
left a comment
There was a problem hiding this comment.
Approving so you can merge once you decide if/how to address my pending feedback.
The
OAuth.AuthTests.CanAuthenticate_WithoutResourceInWwwAuthenticateHeader_WithPathSuffixtest was timing out in CI due to a 10-second HttpClient timeout being insufficient on slow CI machines.Changes
Test Infrastructure
TestConstants.HttpClientTimeout(60s) andHttpClientPollingTimeout(2s)HttpClient.Timeoutvalues in:KestrelInMemoryTest.cs(10s → 60s)ServerConformanceTests.cs(2s → 2s, now centralized)EverythingSseServerFixture.cs(2s → 2s, now centralized)WaitForExitAsynctimeouts withTestConstants.DefaultTimeout(60s):EverythingSseServerFixture.cs(10s → 60s)StdioServerIntegrationTests.cs(10s → 60s)All timeout values that represent test infrastructure concerns (not test logic) are now centralized in
TestConstants.cs. No production code changes are included in this PR.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.