1
0
mirror of https://github.com/ZetaKebab/MpcNET.git synced 2025-01-14 22:18:43 +00:00

Stop running MPD on build server and restart it with own config

This commit is contained in:
glucaci 2016-12-16 13:16:57 +01:00
parent b54500053c
commit 7dd8a6ad1e
2 changed files with 32 additions and 34 deletions

View File

@ -25,12 +25,10 @@ namespace LibMpcTest
var connected = Task.Run(async () => await _mpc.ConnectAsync()).Result; var connected = Task.Run(async () => await _mpc.ConnectAsync()).Result;
if (connected) if (connected)
{ {
Console.Out.WriteLine();
Console.Out.WriteLine("Connected to MPD."); Console.Out.WriteLine("Connected to MPD.");
} }
else else
{ {
Console.Out.WriteLine();
Console.Out.WriteLine("Could not connect to MPD."); Console.Out.WriteLine("Could not connect to MPD.");
} }
} }
@ -40,7 +38,7 @@ namespace LibMpcTest
{ {
var response = await _mpc.SendAsync(new Commands.Reflection.TagTypes()); var response = await _mpc.SendAsync(new Commands.Reflection.TagTypes());
Console.Out.WriteLine(); Console.Out.WriteLine("TagTypesTest Result:");
Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
Assert.True(response.Response.Body.Keys.Contains("tagtypes")); Assert.True(response.Response.Body.Keys.Contains("tagtypes"));
@ -52,7 +50,7 @@ namespace LibMpcTest
{ {
var response = await _mpc.SendAsync(new Commands.Database.ListAll()); var response = await _mpc.SendAsync(new Commands.Database.ListAll());
Console.Out.WriteLine(); Console.Out.WriteLine("ListAllTest Result:");
Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented)); Console.Out.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
// TODO: Assert // TODO: Assert

View File

@ -9,6 +9,11 @@ namespace LibMpcTest
{ {
public MpdServerTest() public MpdServerTest()
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
SendCommand("/usr/bin/pkill mpd");
}
MpdConf.Create(Path.Combine(AppContext.BaseDirectory, "Server")); MpdConf.Create(Path.Combine(AppContext.BaseDirectory, "Server"));
var server = GetServer(); var server = GetServer();
@ -27,44 +32,19 @@ namespace LibMpcTest
} }
}; };
Console.Out.WriteLine();
Console.Out.WriteLine($"Starting Server: {Process.StartInfo.FileName} {Process.StartInfo.Arguments}"); Console.Out.WriteLine($"Starting Server: {Process.StartInfo.FileName} {Process.StartInfo.Arguments}");
Process.Start(); Process.Start();
Console.Out.WriteLine($"Output: {Process.StandardOutput.ReadToEnd()}"); Console.Out.WriteLine($"Output: {Process.StandardOutput.ReadToEnd()}");
Console.Out.WriteLine($"Error: {Process.StandardError.ReadToEnd()}"); Console.Out.WriteLine($"Error: {Process.StandardError.ReadToEnd()}");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{ {
CheckIfServerIsRunning(); SendCommand("/bin/netstat -ntpl");
} }
} }
private void CheckIfServerIsRunning() public Process Process { get; }
{
var netcat = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
WorkingDirectory = "/bin/",
Arguments = "-c \"sudo /bin/netstat -ntpl\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
}
};
netcat.Start();
netcat.WaitForExit();
Console.Out.WriteLine();
Console.Out.WriteLine("netstat -ntpl");
Console.Out.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}");
Console.Out.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}");
}
private Server GetServer() private Server GetServer()
{ {
@ -81,9 +61,29 @@ namespace LibMpcTest
throw new NotSupportedException("OS not supported"); throw new NotSupportedException("OS not supported");
} }
public Process Process { get; } private void SendCommand(string command)
public string LogError { get; } {
public string LogOutput { get; } var netcat = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
WorkingDirectory = "/bin/",
Arguments = $"-c \"sudo {command}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
}
};
netcat.Start();
netcat.WaitForExit();
Console.Out.WriteLine(command);
Console.Out.WriteLine($"Output: {netcat.StandardOutput.ReadToEnd()}");
Console.Out.WriteLine($"Error: {netcat.StandardError.ReadToEnd()}");
}
public void Dispose() public void Dispose()
{ {