diff --git a/tests/mcpdotnet.Tests/EverythingSseServerFixture.cs b/tests/mcpdotnet.Tests/EverythingSseServerFixture.cs index 16d8f33..773ba0f 100644 --- a/tests/mcpdotnet.Tests/EverythingSseServerFixture.cs +++ b/tests/mcpdotnet.Tests/EverythingSseServerFixture.cs @@ -4,21 +4,28 @@ namespace McpDotNet.Tests; public class EverythingSseServerFixture : IAsyncDisposable { - private Process? _process; + private int _port; + private string _containerName; + + public EverythingSseServerFixture(int port) + { + _port = port; + _containerName = $"mcp-everything-server-{_port}"; + } public async Task StartAsync() { var processStartInfo = new ProcessStartInfo { FileName = "docker", - Arguments = "run -p 3001:3001 --rm tzolov/mcp-everything-server:v1", + Arguments = $"run -p {_port}:3001 --name {_containerName} --rm tzolov/mcp-everything-server:v1", RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, }; - _process = Process.Start(processStartInfo) + _ = Process.Start(processStartInfo) ?? throw new InvalidOperationException($"Could not start process for {processStartInfo.FileName} with '{processStartInfo.Arguments}'."); // Wait for the server to start @@ -28,34 +35,18 @@ public class EverythingSseServerFixture : IAsyncDisposable { try { - // Find the container ID - var psInfo = new ProcessStartInfo + + // Stop the container + var stopInfo = new ProcessStartInfo { FileName = "docker", - Arguments = "ps -q --filter ancestor=tzolov/mcp-everything-server:v1", - RedirectStandardOutput = true, + Arguments = $"stop {_containerName}", UseShellExecute = false }; - using var psProcess = Process.Start(psInfo) - ?? throw new InvalidOperationException($"Could not start process for {psInfo.FileName} with '{psInfo.Arguments}'."); - string containerId = await psProcess.StandardOutput.ReadToEndAsync(); - containerId = containerId.Trim(); - - if (!string.IsNullOrEmpty(containerId)) - { - // Stop the container - var stopInfo = new ProcessStartInfo - { - FileName = "docker", - Arguments = $"stop {containerId}", - UseShellExecute = false - }; - - using var stopProcess = Process.Start(stopInfo) - ?? throw new InvalidOperationException($"Could not start process for {stopInfo.FileName} with '{stopInfo.Arguments}'."); - await stopProcess.WaitForExitAsync(); - } + using var stopProcess = Process.Start(stopInfo) + ?? throw new InvalidOperationException($"Could not stop process for {stopInfo.FileName} with '{stopInfo.Arguments}'."); + await stopProcess.WaitForExitAsync(); } catch (Exception ex) { diff --git a/tests/mcpdotnet.Tests/SseIntegrationTests.cs b/tests/mcpdotnet.Tests/SseIntegrationTests.cs index 7fdec8d..e291fa9 100644 --- a/tests/mcpdotnet.Tests/SseIntegrationTests.cs +++ b/tests/mcpdotnet.Tests/SseIntegrationTests.cs @@ -56,13 +56,16 @@ public class SseIntegrationTests } [Fact] + [Trait("Execution", "Manual")] public async Task ConnectAndReceiveMessage_EverythingServerWithSse() { using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(builder => builder.AddConsole() .SetMinimumLevel(LogLevel.Debug)); - await using var fixture = new EverythingSseServerFixture(); + int port = 3001; + + await using var fixture = new EverythingSseServerFixture(port); await fixture.StartAsync(); var defaultOptions = new McpClientOptions @@ -76,7 +79,7 @@ public class SseIntegrationTests Name = "Everything", TransportType = TransportTypes.Sse, TransportOptions = [], - Location = "http://localhost:3001/sse" + Location = $"http://localhost:{port}/sse" }; using var factory = new McpClientFactory( @@ -94,6 +97,7 @@ public class SseIntegrationTests } [Fact] + [Trait("Execution", "Manual")] public async Task Sampling_Sse_EverythingServer() { // arrange @@ -101,7 +105,9 @@ public class SseIntegrationTests builder.AddConsole() .SetMinimumLevel(LogLevel.Debug)); - await using var fixture = new EverythingSseServerFixture(); + int port = 3002; + + await using var fixture = new EverythingSseServerFixture(port); await fixture.StartAsync(); var defaultOptions = new McpClientOptions @@ -123,7 +129,7 @@ public class SseIntegrationTests Name = "Everything", TransportType = TransportTypes.Sse, TransportOptions = [], - Location = "http://localhost:3001/sse" + Location = $"http://localhost:{port}/sse" }; using var factory = new McpClientFactory(