@@ -8,6 +8,20 @@ namespace ModelContextProtocol.Tests;
88
99public class SseIntegrationTests ( ITestOutputHelper outputHelper ) : LoggedTest ( outputHelper )
1010{
11+ /// <summary>Port number to be grabbed by the next test.</summary>
12+ private static int s_nextPort = 3000 ;
13+
14+ // If the tests run concurrently against different versions of the runtime, tests can conflict with
15+ // each other in the ports set up for interacting with containers. Ensure that such suites running
16+ // against different TFMs use different port numbers.
17+ private static readonly int s_portOffset = 1000 * ( Environment . Version . Major switch
18+ {
19+ int v when v >= 8 => Environment . Version . Major - 7 ,
20+ _ => 0 ,
21+ } ) ;
22+
23+ private static int CreatePortNumber ( ) => Interlocked . Increment ( ref s_nextPort ) + s_portOffset ;
24+
1125 [ Fact ]
1226 public async Task ConnectAndReceiveMessage_InMemoryServer ( )
1327 {
@@ -52,7 +66,7 @@ public async Task ConnectAndReceiveMessage_EverythingServerWithSse()
5266 {
5367 Assert . SkipWhen ( ! EverythingSseServerFixture . IsDockerAvailable , "docker is not available" ) ;
5468
55- int port = 3001 ;
69+ int port = CreatePortNumber ( ) ;
5670
5771 await using var fixture = new EverythingSseServerFixture ( port ) ;
5872 await fixture . StartAsync ( ) ;
@@ -89,7 +103,7 @@ public async Task Sampling_Sse_EverythingServer()
89103 {
90104 Assert . SkipWhen ( ! EverythingSseServerFixture . IsDockerAvailable , "docker is not available" ) ;
91105
92- int port = 3002 ;
106+ int port = CreatePortNumber ( ) ;
93107
94108 await using var fixture = new EverythingSseServerFixture ( port ) ;
95109 await fixture . StartAsync ( ) ;
@@ -161,7 +175,6 @@ public async Task ConnectAndReceiveMessage_InMemoryServer_WithFullEndpointEventU
161175 server . UseFullUrlForEndpointEvent = true ;
162176 await server . StartAsync ( ) ;
163177
164-
165178 var defaultOptions = new McpClientOptions
166179 {
167180 ClientInfo = new ( ) { Name = "IntegrationTestClient" , Version = "1.0.0" }
0 commit comments