|
|
|
@ -3,6 +3,7 @@ using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common.Model;
|
|
|
|
@ -64,12 +65,30 @@ namespace NzbDrone.Common.Test
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Should_be_able_to_start_process()
|
|
|
|
|
public void should_be_able_to_start_process()
|
|
|
|
|
{
|
|
|
|
|
var process = StartDummyProcess();
|
|
|
|
|
|
|
|
|
|
var check = Subject.GetProcessById(process.Id);
|
|
|
|
|
check.Should().NotBeNull();
|
|
|
|
|
|
|
|
|
|
process.Refresh();
|
|
|
|
|
process.HasExited.Should().BeFalse();
|
|
|
|
|
|
|
|
|
|
process.Kill();
|
|
|
|
|
process.WaitForExit();
|
|
|
|
|
process.HasExited.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Platform(Exclude="MacOsX")]
|
|
|
|
|
[Retry(3)]
|
|
|
|
|
public void exists_should_find_running_process()
|
|
|
|
|
{
|
|
|
|
|
var process = StartDummyProcess();
|
|
|
|
|
|
|
|
|
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
|
|
|
|
.BeTrue("excepted one dummy process to be already running");
|
|
|
|
|
.BeTrue("expected one dummy process to be already running");
|
|
|
|
|
|
|
|
|
|
process.Kill();
|
|
|
|
|
process.WaitForExit();
|
|
|
|
@ -126,8 +145,8 @@ namespace NzbDrone.Common.Test
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Platform(Exclude="MacOsX")]
|
|
|
|
|
public void kill_all_should_kill_all_process_with_name()
|
|
|
|
|
{
|
|
|
|
|
var dummy1 = StartDummyProcess();
|
|
|
|
@ -141,15 +160,30 @@ namespace NzbDrone.Common.Test
|
|
|
|
|
|
|
|
|
|
private Process StartDummyProcess()
|
|
|
|
|
{
|
|
|
|
|
var processStarted = new ManualResetEventSlim();
|
|
|
|
|
|
|
|
|
|
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
|
|
|
|
return Subject.Start(path);
|
|
|
|
|
var process = Subject.Start(path, onOutputDataReceived: (string data) => {
|
|
|
|
|
if (data.StartsWith("Dummy process. ID:"))
|
|
|
|
|
{
|
|
|
|
|
processStarted.Set();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!processStarted.Wait(2000))
|
|
|
|
|
{
|
|
|
|
|
Assert.Fail("Failed to start process within 2 sec");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return process;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Retry(3)]
|
|
|
|
|
public void ToString_on_new_processInfo()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(new ProcessInfo().ToString());
|
|
|
|
|
ExceptionVerification.MarkInconclusive(typeof(Win32Exception));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|