Skip to content

Ensure that Run tests (http) is actually testing http - #3340

Open
Chidozie Ononiwu (chidozieononiwu) wants to merge 6 commits into
microsoft:mainfrom
chidozieononiwu:ensureHttpTesting
Open

Ensure that Run tests (http) is actually testing http#3340
Chidozie Ononiwu (chidozieononiwu) wants to merge 6 commits into
microsoft:mainfrom
chidozieononiwu:ensureHttpTesting

Conversation

@chidozieononiwu

@chidozieononiwu Chidozie Ononiwu (chidozieononiwu) commented Aug 20, 2026

Copy link
Copy Markdown
Member

This pull request improves test reliability and error handling for unsupported operations when running in HTTP transport mode. It introduces a shared assertion helper to standardize checks for "method not found" errors, updates tests to use this helper, and ensures that tool command tests gracefully skip or verify expected failures in HTTP mode. Additionally, it enhances server readiness checks to handle process exits robustly.

Test reliability and error handling improvements:

  • Refactored multiple tests in ClientToolTests.cs to use a new AssertMethodNotFoundAsync helper, which standardizes assertions for unsupported method errors and properly distinguishes between protocol and HTTP transport modes. [1] [2]
  • Added the AssertMethodNotFoundAsync helper to handle both McpProtocolException and HttpRequestException, depending on the test transport, improving clarity and reducing duplication.

Server readiness and process management:

  • Updated StartHttpServerProcessAndWaitForReadinessAsync and WaitForServerReadinessAsync in McpTestUtilities.cs to support cancellation and detect if the server process exits before becoming ready, throwing a clear exception in that case. [1] [2] [3] [4]

Live test pipeline configuration:

  • Set the MCP_TEST_TRANSPORT environment variable to 'http' in the live test pipeline to ensure tests run in the correct mode.

Tool command test robustness in HTTP mode:

  • Updated tests for Azure Migrate, Key Vault, and Storage tool commands to check for HTTP mode and assert that commands are unavailable as expected, preventing false failures in unsupported scenarios. [1] [2] [3] [4] [5] [6] [7]

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Azure Pipelines live-test job template to ensure the “Run tests (http)” step actually executes the test suite using the HTTP transport, aligning the pipeline behavior with the step’s intent and label.

Changes:

  • Sets MCP_TEST_TRANSPORT to http for the “Run tests (http) - az pwsh” task to force HTTP-based test transport selection during that run.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@vukelich

Copy link
Copy Markdown
Member

/azp run mcp - pullrequest - live

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread eng/pipelines/templates/jobs/live-test.yml
@chidozieononiwu

Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@chidozieononiwu

Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@chidozieononiwu

Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@chidozieononiwu

Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@chidozieononiwu

Copy link
Copy Markdown
Member Author

/azp run mcp - pullrequest - live

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

"prompts/get");
}

private static async Task AssertMethodNotFoundAsync(Func<Task> action, string method)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment in this code that explains why we're treating the modes separately. Your comment may be anecdotal and point to observations of the specific C# MCP SDK version we're seeing this transport-dependent exception behavior with.

Adding this comment will help other maintainers know why this is happening and crucially learn its outside of our control and outside the scope of us understanding. If the C# MCP SDK behavior changes to be consistent between the transport modes, then a contextual comment here will empower someone to make a quick reactive change without needing to investigate the history of this code.

As a general rule, if we ever learn something unintuitive that causes us to conditionalize code, then it's worth documenting in code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think this is worth bringing up with the C# MCP SDK as well. I'd like to learn if this is intentional or not, and if it is intentional, to learn how we might have other error handling scenarios wrong.

Comment on lines +245 to +253
using var readinessCancellation = new CancellationTokenSource();
var readinessTask = WaitForServerReadinessAsync(
serverUrl,
timeoutSeconds,
pollIntervalMs,
authenticationEnabled: !disableAuthentication,
readinessCancellation.Token);
var processExitTask = process.WaitForExitAsync();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This process start code is not using the Xunit.TestContext.Current.CancellationToken.

Use that token as a CancellationToken to process.WaitForExitAsync();

Leverage CancellationTokenSource.CreateLinkedTokenSource() when making new CancellationTokenSources. using var readinessCancellation = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);

You will want to think about what happens if the harnesses cancellation is set and if you need to adjust this code accordingly, e.g., do you need to add code for catching TaskCanceledException here or let it bubble up?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants