Fix docker based integration tests to be more robust (#74)

* Fix docker based integration tests to be more robust
* Make docker based integration tests manual
This commit is contained in:
Peder Holdgaard Pedersen 2025-03-15 20:56:46 +01:00 • committed by GitHub
commit 7bf450e443
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 30 deletions

View file

@ -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)
{

View file

@ -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(