Skip to content

Commit 515db78

Browse files
Copilothalter73
andcommitted
Replace Task.Delay with GetTaskResultAsync in task-path tests
Use GetTaskResultAsync to wait for task completion instead of arbitrary Task.Delay(500) calls, making tests deterministic and faster. Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
1 parent c18f406 commit 515db78

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/ModelContextProtocol.Tests/Server/ToolTaskSupportTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ public async Task TaskPath_Logs_Tool_Name_On_Successful_Call()
564564

565565
Assert.NotNull(mcpTask);
566566

567-
// Wait briefly for the async task execution to complete
568-
await Task.Delay(500, TestContext.Current.CancellationToken);
567+
// Wait for the async task execution to complete
568+
await fixture.Client.GetTaskResultAsync(mcpTask.TaskId, cancellationToken: TestContext.Current.CancellationToken);
569569

570570
var infoLog = Assert.Single(MockLoggerProvider.LogMessages, m => m.Message == "\"task-success-tool\" completed. IsError = False.");
571571
Assert.Equal(LogLevel.Information, infoLog.LogLevel);
@@ -607,8 +607,8 @@ public async Task TaskPath_Logs_Tool_Name_With_IsError_When_Tool_Returns_Error()
607607

608608
Assert.NotNull(mcpTask);
609609

610-
// Wait briefly for the async task execution to complete
611-
await Task.Delay(500, TestContext.Current.CancellationToken);
610+
// Wait for the async task execution to complete
611+
await fixture.Client.GetTaskResultAsync(mcpTask.TaskId, cancellationToken: TestContext.Current.CancellationToken);
612612

613613
var infoLog = Assert.Single(MockLoggerProvider.LogMessages, m => m.Message == "\"task-error-result-tool\" completed. IsError = True.");
614614
Assert.Equal(LogLevel.Information, infoLog.LogLevel);
@@ -646,8 +646,8 @@ public async Task TaskPath_Logs_Error_When_Tool_Throws()
646646

647647
Assert.NotNull(mcpTask);
648648

649-
// Wait briefly for the async task execution to complete
650-
await Task.Delay(500, TestContext.Current.CancellationToken);
649+
// Wait for the async task execution to complete
650+
await fixture.Client.GetTaskResultAsync(mcpTask.TaskId, cancellationToken: TestContext.Current.CancellationToken);
651651

652652
var errorLog = Assert.Single(MockLoggerProvider.LogMessages, m => m.LogLevel == LogLevel.Error);
653653
Assert.Equal("\"task-throw-tool\" threw an unhandled exception.", errorLog.Message);

0 commit comments

Comments
 (0)