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:
parent
729c8b5eb9
commit
7bf450e443
2 changed files with 27 additions and 30 deletions
|
|
@ -4,21 +4,28 @@ namespace McpDotNet.Tests;
|
||||||
|
|
||||||
public class EverythingSseServerFixture : IAsyncDisposable
|
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()
|
public async Task StartAsync()
|
||||||
{
|
{
|
||||||
var processStartInfo = new ProcessStartInfo
|
var processStartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "docker",
|
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,
|
RedirectStandardInput = true,
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true,
|
RedirectStandardError = true,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
_process = Process.Start(processStartInfo)
|
_ = Process.Start(processStartInfo)
|
||||||
?? throw new InvalidOperationException($"Could not start process for {processStartInfo.FileName} with '{processStartInfo.Arguments}'.");
|
?? throw new InvalidOperationException($"Could not start process for {processStartInfo.FileName} with '{processStartInfo.Arguments}'.");
|
||||||
|
|
||||||
// Wait for the server to start
|
// Wait for the server to start
|
||||||
|
|
@ -28,34 +35,18 @@ public class EverythingSseServerFixture : IAsyncDisposable
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Find the container ID
|
|
||||||
var psInfo = new ProcessStartInfo
|
// Stop the container
|
||||||
|
var stopInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "docker",
|
FileName = "docker",
|
||||||
Arguments = "ps -q --filter ancestor=tzolov/mcp-everything-server:v1",
|
Arguments = $"stop {_containerName}",
|
||||||
RedirectStandardOutput = true,
|
|
||||||
UseShellExecute = false
|
UseShellExecute = false
|
||||||
};
|
};
|
||||||
|
|
||||||
using var psProcess = Process.Start(psInfo)
|
using var stopProcess = Process.Start(stopInfo)
|
||||||
?? throw new InvalidOperationException($"Could not start process for {psInfo.FileName} with '{psInfo.Arguments}'.");
|
?? throw new InvalidOperationException($"Could not stop process for {stopInfo.FileName} with '{stopInfo.Arguments}'.");
|
||||||
string containerId = await psProcess.StandardOutput.ReadToEndAsync();
|
await stopProcess.WaitForExitAsync();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,16 @@ public class SseIntegrationTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
[Trait("Execution", "Manual")]
|
||||||
public async Task ConnectAndReceiveMessage_EverythingServerWithSse()
|
public async Task ConnectAndReceiveMessage_EverythingServerWithSse()
|
||||||
{
|
{
|
||||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
|
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
|
||||||
builder.AddConsole()
|
builder.AddConsole()
|
||||||
.SetMinimumLevel(LogLevel.Debug));
|
.SetMinimumLevel(LogLevel.Debug));
|
||||||
|
|
||||||
await using var fixture = new EverythingSseServerFixture();
|
int port = 3001;
|
||||||
|
|
||||||
|
await using var fixture = new EverythingSseServerFixture(port);
|
||||||
await fixture.StartAsync();
|
await fixture.StartAsync();
|
||||||
|
|
||||||
var defaultOptions = new McpClientOptions
|
var defaultOptions = new McpClientOptions
|
||||||
|
|
@ -76,7 +79,7 @@ public class SseIntegrationTests
|
||||||
Name = "Everything",
|
Name = "Everything",
|
||||||
TransportType = TransportTypes.Sse,
|
TransportType = TransportTypes.Sse,
|
||||||
TransportOptions = [],
|
TransportOptions = [],
|
||||||
Location = "http://localhost:3001/sse"
|
Location = $"http://localhost:{port}/sse"
|
||||||
};
|
};
|
||||||
|
|
||||||
using var factory = new McpClientFactory(
|
using var factory = new McpClientFactory(
|
||||||
|
|
@ -94,6 +97,7 @@ public class SseIntegrationTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
[Trait("Execution", "Manual")]
|
||||||
public async Task Sampling_Sse_EverythingServer()
|
public async Task Sampling_Sse_EverythingServer()
|
||||||
{
|
{
|
||||||
// arrange
|
// arrange
|
||||||
|
|
@ -101,7 +105,9 @@ public class SseIntegrationTests
|
||||||
builder.AddConsole()
|
builder.AddConsole()
|
||||||
.SetMinimumLevel(LogLevel.Debug));
|
.SetMinimumLevel(LogLevel.Debug));
|
||||||
|
|
||||||
await using var fixture = new EverythingSseServerFixture();
|
int port = 3002;
|
||||||
|
|
||||||
|
await using var fixture = new EverythingSseServerFixture(port);
|
||||||
await fixture.StartAsync();
|
await fixture.StartAsync();
|
||||||
|
|
||||||
var defaultOptions = new McpClientOptions
|
var defaultOptions = new McpClientOptions
|
||||||
|
|
@ -123,7 +129,7 @@ public class SseIntegrationTests
|
||||||
Name = "Everything",
|
Name = "Everything",
|
||||||
TransportType = TransportTypes.Sse,
|
TransportType = TransportTypes.Sse,
|
||||||
TransportOptions = [],
|
TransportOptions = [],
|
||||||
Location = "http://localhost:3001/sse"
|
Location = $"http://localhost:{port}/sse"
|
||||||
};
|
};
|
||||||
|
|
||||||
using var factory = new McpClientFactory(
|
using var factory = new McpClientFactory(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue