1
- using ModelContextProtocol . Client ;
1
+ using Microsoft . Extensions . Logging ;
2
+ using ModelContextProtocol . Client ;
2
3
using ModelContextProtocol . Configuration ;
3
4
using ModelContextProtocol . Protocol . Transport ;
4
- using Microsoft . Extensions . Logging ;
5
- using System . Diagnostics ;
6
- using System . Diagnostics . CodeAnalysis ;
7
5
8
6
namespace ModelContextProtocol . Tests ;
9
7
10
- public class SseServerIntegrationTestFixture : IDisposable
8
+ public class SseServerIntegrationTestFixture : IAsyncDisposable
11
9
{
12
- private Process _process ;
10
+ private readonly CancellationTokenSource _stopCts = new ( ) ;
11
+ private readonly Task _serverTask ;
13
12
14
13
public ILoggerFactory LoggerFactory { get ; }
15
14
public McpClientOptions DefaultOptions { get ; }
@@ -35,40 +34,20 @@ public SseServerIntegrationTestFixture()
35
34
Location = "http://localhost:3001/sse"
36
35
} ;
37
36
38
- Start ( ) ;
37
+ _serverTask = TestSseServer . Program . MainAsync ( [ ] , _stopCts . Token ) ;
39
38
}
40
39
41
- [ MemberNotNull ( nameof ( _process ) ) ]
42
- public void Start ( )
43
- {
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 ( )
40
+ public async ValueTask DisposeAsync ( )
63
41
{
42
+ LoggerFactory . Dispose ( ) ;
43
+ _stopCts . Cancel ( ) ;
64
44
try
65
45
{
66
- LoggerFactory ? . Dispose ( ) ;
46
+ await _serverTask . ConfigureAwait ( false ) ;
67
47
}
68
- finally
48
+ catch ( OperationCanceledException )
69
49
{
70
- // Kill the server process
71
- _process . Kill ( ) ;
72
50
}
51
+ _stopCts . Dispose ( ) ;
73
52
}
74
53
}
0 commit comments