Skip to content

Stabilize task cancellation cleanup test#1712

Open
lntutor wants to merge 1 commit into
modelcontextprotocol:mainfrom
lntutor:test/await-task-cancellation-1701
Open

Stabilize task cancellation cleanup test#1712
lntutor wants to merge 1 commit into
modelcontextprotocol:mainfrom
lntutor:test/await-task-cancellation-1701

Conversation

@lntutor

@lntutor lntutor commented Jul 19, 2026

Copy link
Copy Markdown

Fixes #1701.

Summary

TaskTool_CancellationToken_GetTaskShowsWorkingBeforeCancel cancelled its infinite-delay tool during cleanup but immediately began client/server teardown. Unlike the adjacent explicit-cancellation test, it never waited for the tool to observe cancellation, leaving teardown to race a still-running request.

This waits on the test’s existing _toolCancellationFired signal with TestConstants.DefaultTimeout and the xUnit cancellation token before disposal.

Tests

  • focused test run three consecutive times (9 target-framework executions passed)
  • full TaskCancellationIntegrationTests class (6 passed)
  • dotnet build ModelContextProtocol.slnx (36 projects, 0 warnings)
  • targeted dotnet format --verify-no-changes
  • full ModelContextProtocol.Tests project: 6,864 passed; the three failures are DockerEverythingServerTests.Sampling_Sse_EverythingServer, which reproduce on clean upstream/main because the local Everything Server container lacks trigger-sampling-request


// Cleanup
await client.CancelTaskAsync(taskId, ct);
await _toolCancellationFired.Task.WaitAsync(TestConstants.DefaultTimeout, ct);

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.

The other tests wait for this condition to assert that a client cancel makes its way into the server tool call and the cancellation is actually observed. This test is not validating that so it's not needed.

The correct cleanup should actually be handled by the server during disposal. This is a separate issue tracked in #1707.

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.

Flaky test host hang on Windows Debug CI: TaskCancellationIntegrationTests.TaskTool_CancellationToken_GetTaskShowsWorkingBeforeCancel

2 participants