From 091ec312c8bdb5bc30573dd29875f3e0704b5528 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 13 Aug 2013 07:39:00 -0700 Subject: [PATCH] fixed multiple instances starting when updateing nzbdrone --- NzbDrone.Common.Test/ProcessProviderTests.cs | 35 +++++++++++++++++--- NzbDrone.Common/ProcessProvider.cs | 1 - 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/NzbDrone.Common.Test/ProcessProviderTests.cs b/NzbDrone.Common.Test/ProcessProviderTests.cs index 126464107..a5b2d0b1b 100644 --- a/NzbDrone.Common.Test/ProcessProviderTests.cs +++ b/NzbDrone.Common.Test/ProcessProviderTests.cs @@ -18,7 +18,13 @@ public class ProcessProviderTests : TestBase [SetUp] public void Setup() { - Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => c.Kill()); + Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => + { + c.Kill(); + c.WaitForExit(); + }); + + Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).Should().BeEmpty(); } [TearDown] @@ -51,13 +57,32 @@ public void Should_be_able_to_start_process() { var startInfo = new ProcessStartInfo(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe")); - - Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should() - .BeFalse("Dummy process is already running"); - Subject.Start(startInfo).Should().NotBeNull(); + var process = Subject.Start(startInfo); Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should() .BeTrue("excepted one dummy process to be already running"); + + process.Kill(); + process.WaitForExit(); + + Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse(); + } + + + + [Test] + public void Should_be_able_to_execute_process() + { + var process = Subject.ShellExecute(Path.Combine(Directory.GetCurrentDirectory(), DummyApp.DUMMY_PROCCESS_NAME + ".exe")); + + + Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should() + .BeTrue("excepted one dummy process to be already running"); + + process.Kill(); + process.WaitForExit(); + + Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should().BeFalse(); } [Test] diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs index 4b5abaf50..b0ba88f08 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/ProcessProvider.cs @@ -124,7 +124,6 @@ public Process ShellExecute(string path, string args = null, Action onOu process.BeginErrorReadLine(); process.BeginOutputReadLine(); - process.Start(); return process; }