Skip to content

Commit 8513ccb

Browse files
committed
Handle expected OCE disposing fixture
1 parent 152b1ca commit 8513ccb

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

tests/ModelContextProtocol.TestSseServer/Program.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ private static ILoggerFactory CreateLoggerFactory()
2727
});
2828
}
2929

30-
public static Task Main(string[] args) => MainAsync(args, CancellationToken.None);
30+
public static Task Main(string[] args) => MainAsync(args);
3131

32-
public static async Task MainAsync(string[] args, CancellationToken cancellationToken)
32+
public static async Task MainAsync(string[] args, CancellationToken cancellationToken = default)
3333
{
3434
Console.WriteLine("Starting server...");
3535

@@ -394,8 +394,15 @@ static CreateMessageRequestParams CreateRequestSamplingParams(string context, st
394394

395395
Console.WriteLine("Server started.");
396396

397-
// Run until process is stopped by the client (parent process)
398-
await Task.Delay(Timeout.Infinite, cancellationToken);
397+
try
398+
{
399+
// Run until process is stopped by the client (parent process) or test
400+
await Task.Delay(Timeout.Infinite, cancellationToken);
401+
}
402+
finally
403+
{
404+
await server.DisposeAsync();
405+
}
399406
}
400407

401408
const string MCP_TINY_IMAGE =

tests/ModelContextProtocol.Tests/SseServerIntegrationTestFixture.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public async ValueTask DisposeAsync()
4141
{
4242
LoggerFactory.Dispose();
4343
_stopCts.Cancel();
44-
await _serverTask.ConfigureAwait(false);
44+
try
45+
{
46+
await _serverTask.ConfigureAwait(false);
47+
}
48+
catch (OperationCanceledException)
49+
{
50+
}
4551
_stopCts.Dispose();
4652
}
4753
}

0 commit comments

Comments
 (0)