Skip to content

Commit

Permalink
Fixed: Make ProcessProviderTests less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
ta264 authored and Qstick committed Aug 24, 2019
1 parent ee7d47d commit 1a0b95d
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/NzbDrone.Common.Test/ProcessProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Model;
Expand All @@ -12,6 +13,8 @@

namespace NzbDrone.Common.Test
{
// We don't want one tests setup killing processes used in another
[NonParallelizable]
[TestFixture]
public class ProcessProviderTests : TestBase<ProcessProvider>
{
Expand Down Expand Up @@ -63,9 +66,25 @@ public void GetProcessById_should_return_null_for_invalid_process(int processId)
ExceptionVerification.ExpectedWarns(1);
}

[Test]
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")]
public void Should_be_able_to_start_process()
public void exists_should_find_running_process()
{
var process = StartDummyProcess();

Expand Down Expand Up @@ -94,8 +113,22 @@ public void kill_all_should_kill_all_process_with_name()

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]
Expand Down

0 comments on commit 1a0b95d

Please sign in to comment.