|
|
@ -16,6 +16,7 @@ namespace NzbDrone.Common.Test
|
|
|
|
// We don't want one tests setup killing processes used in another
|
|
|
|
// We don't want one tests setup killing processes used in another
|
|
|
|
[NonParallelizable]
|
|
|
|
[NonParallelizable]
|
|
|
|
[TestFixture]
|
|
|
|
[TestFixture]
|
|
|
|
|
|
|
|
[Platform(Exclude = "MacOsX")]
|
|
|
|
public class ProcessProviderFixture : TestBase<ProcessProvider>
|
|
|
|
public class ProcessProviderFixture : TestBase<ProcessProvider>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
@ -71,20 +72,18 @@ namespace NzbDrone.Common.Test
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var process = StartDummyProcess();
|
|
|
|
var process = StartDummyProcess();
|
|
|
|
|
|
|
|
|
|
|
|
var check = Subject.GetProcessById(process.Id);
|
|
|
|
Thread.Sleep(500);
|
|
|
|
check.Should().NotBeNull();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process.Refresh();
|
|
|
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
|
|
|
|
process.HasExited.Should().BeFalse();
|
|
|
|
.BeTrue("one running dummy process");
|
|
|
|
|
|
|
|
|
|
|
|
process.Kill();
|
|
|
|
process.Kill();
|
|
|
|
process.WaitForExit();
|
|
|
|
process.WaitForExit();
|
|
|
|
process.HasExited.Should().BeTrue();
|
|
|
|
|
|
|
|
|
|
|
|
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
[Platform(Exclude="MacOsX")]
|
|
|
|
|
|
|
|
[Retry(3)]
|
|
|
|
|
|
|
|
public void exists_should_find_running_process()
|
|
|
|
public void exists_should_find_running_process()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var process = StartDummyProcess();
|
|
|
|
var process = StartDummyProcess();
|
|
|
@ -100,12 +99,13 @@ namespace NzbDrone.Common.Test
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
[Platform(Exclude="MacOsX")]
|
|
|
|
|
|
|
|
public void kill_all_should_kill_all_process_with_name()
|
|
|
|
public void kill_all_should_kill_all_process_with_name()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var dummy1 = StartDummyProcess();
|
|
|
|
var dummy1 = StartDummyProcess();
|
|
|
|
var dummy2 = StartDummyProcess();
|
|
|
|
var dummy2 = StartDummyProcess();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
|
|
|
|
|
|
|
Subject.KillAll(DummyApp.DUMMY_PROCCESS_NAME);
|
|
|
|
Subject.KillAll(DummyApp.DUMMY_PROCCESS_NAME);
|
|
|
|
|
|
|
|
|
|
|
|
dummy1.HasExited.Should().BeTrue();
|
|
|
|
dummy1.HasExited.Should().BeTrue();
|
|
|
@ -114,26 +114,11 @@ namespace NzbDrone.Common.Test
|
|
|
|
|
|
|
|
|
|
|
|
private Process StartDummyProcess()
|
|
|
|
private Process StartDummyProcess()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var processStarted = new ManualResetEventSlim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
|
|
|
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, DummyApp.DUMMY_PROCCESS_NAME + ".exe");
|
|
|
|
var process = Subject.Start(path, onOutputDataReceived: (string data) => {
|
|
|
|
return Subject.Start(path);
|
|
|
|
if (data.StartsWith("Dummy process. ID:"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
processStarted.Set();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!processStarted.Wait(2000))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert.Fail("Failed to start process within 2 sec");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return process;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Test]
|
|
|
|
[Retry(3)]
|
|
|
|
|
|
|
|
public void ToString_on_new_processInfo()
|
|
|
|
public void ToString_on_new_processInfo()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine(new ProcessInfo().ToString());
|
|
|
|
Console.WriteLine(new ProcessInfo().ToString());
|
|
|
|