1- using ModelContextProtocol . Client ;
1+ using Microsoft . Extensions . Logging ;
2+ using ModelContextProtocol . Client ;
23using ModelContextProtocol . Configuration ;
34using ModelContextProtocol . Protocol . Transport ;
4- using Microsoft . Extensions . Logging ;
5- using System . Diagnostics ;
6- using System . Diagnostics . CodeAnalysis ;
75
86namespace ModelContextProtocol . Tests ;
97
10- public class SseServerIntegrationTestFixture : IDisposable
8+ public class SseServerIntegrationTestFixture : IAsyncDisposable
119{
12- private Process _process ;
10+ private readonly CancellationTokenSource _stopCts = new ( ) ;
11+ private readonly Task _serverTask ;
1312
1413 public ILoggerFactory LoggerFactory { get ; }
1514 public McpClientOptions DefaultOptions { get ; }
@@ -35,40 +34,14 @@ public SseServerIntegrationTestFixture()
3534 Location = "http://localhost:3001/sse"
3635 } ;
3736
38- Start ( ) ;
37+ _serverTask = TestSseServer . Program . MainAsync ( [ ] , _stopCts . Token ) ;
3938 }
4039
41- [ MemberNotNull ( nameof ( _process ) ) ]
42- public void Start ( )
40+ public async ValueTask DisposeAsync ( )
4341 {
44- // Start the server (which is at TestSseServer.exe on windows and "dotnet TestSseServer.dll" on linux)
45- var processStartInfo = new ProcessStartInfo
46- {
47- FileName = OperatingSystem . IsWindows ( ) ? "TestSseServer.exe" : "dotnet" ,
48- Arguments = "TestSseServer.dll" ,
49- RedirectStandardInput = true ,
50- RedirectStandardOutput = true ,
51- RedirectStandardError = true ,
52- UseShellExecute = false ,
53- } ;
54-
55- _process = Process . Start ( processStartInfo )
56- ?? throw new InvalidOperationException ( $ "Could not start process for { processStartInfo . FileName } with '{ processStartInfo . Arguments } '.") ;
57-
58- // Wait 1 second
59- Thread . Sleep ( 1000 ) ;
60- }
61-
62- public void Dispose ( )
63- {
64- try
65- {
66- LoggerFactory ? . Dispose ( ) ;
67- }
68- finally
69- {
70- // Kill the server process
71- _process . Kill ( ) ;
72- }
42+ LoggerFactory . Dispose ( ) ;
43+ _stopCts . Cancel ( ) ;
44+ await _serverTask . ConfigureAwait ( false ) ;
45+ _stopCts . Dispose ( ) ;
7346 }
7447}
0 commit comments