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
1 changed files with 27 additions and 30 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue