Fixed: several failing/flaky mono unit tests

Co-Authored-By: taloth <taloth@users.noreply.github.com>
pull/6/head
Qstick 5 years ago
parent 9711a0cc9c
commit 7ffecf6c50

@ -25,13 +25,6 @@ namespace NzbDrone.Common.Test.DiskTests
Subject.GetAvailableSpace(Path.Combine(path, "invalidFolder")).Should().NotBe(0); Subject.GetAvailableSpace(Path.Combine(path, "invalidFolder")).Should().NotBe(0);
} }
[Test]
public void should_be_able_to_check_space_on_ramdrive()
{
MonoOnly();
Subject.GetAvailableSpace("/run/").Should().NotBe(0);
}
[Test] [Test]
public void should_return_free_disk_space() public void should_return_free_disk_space()
{ {
@ -39,33 +32,6 @@ namespace NzbDrone.Common.Test.DiskTests
result.Should().BeGreaterThan(0); result.Should().BeGreaterThan(0);
} }
[Test]
public void should_be_able_to_get_space_on_unc()
{
WindowsOnly();
var result = Subject.GetAvailableSpace(@"\\localhost\c$\Windows");
result.Should().BeGreaterThan(0);
}
[Test]
public void should_throw_if_drive_doesnt_exist()
{
WindowsOnly();
// Find a drive that doesn't exist.
for (char driveletter = 'Z'; driveletter > 'D' ; driveletter--)
{
if (new DriveInfo(driveletter.ToString()).IsReady)
continue;
Assert.Throws<DirectoryNotFoundException>(() => Subject.GetAvailableSpace(driveletter + @":\NOT_A_REAL_PATH\DOES_NOT_EXIST".AsOsAgnostic()));
return;
}
Assert.Inconclusive("No drive available for testing.");
}
[Test] [Test]
public void should_be_able_to_get_space_on_folder_that_doesnt_exist() public void should_be_able_to_get_space_on_folder_that_doesnt_exist()
{ {

@ -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());

@ -54,7 +54,6 @@ namespace NzbDrone.Common.Composition
var factory = CreateSingletonImplementationFactory(implementation); var factory = CreateSingletonImplementationFactory(implementation);
_container.Register(service, factory); _container.Register(service, factory);
_container.Register(service, factory, implementation.FullName);
} }
public IEnumerable<T> ResolveAll<T>() where T : class public IEnumerable<T> ResolveAll<T>() where T : class

@ -71,9 +71,9 @@ namespace NzbDrone.Core.Test.Messaging.Commands
_commandQueue.Add(commandModel); _commandQueue.Add(commandModel);
if (!waitEventComplete.Wait(2000)) if (!waitEventComplete.Wait(15000))
{ {
Assert.Fail("Command did not Complete/Fail within 2 sec"); Assert.Fail("Command did not Complete/Fail within 15 sec");
} }
if (waitPublish && !waitEventPublish.Wait(500)) if (waitPublish && !waitEventPublish.Wait(500))
@ -141,7 +141,7 @@ namespace NzbDrone.Core.Test.Messaging.Commands
Subject.Handle(new ApplicationStartedEvent()); Subject.Handle(new ApplicationStartedEvent());
QueueAndWaitForExecution(commandModel); QueueAndWaitForExecution(commandModel, true);
VerifyEventPublished<CommandExecutedEvent>(); VerifyEventPublished<CommandExecutedEvent>();
@ -160,7 +160,7 @@ namespace NzbDrone.Core.Test.Messaging.Commands
Subject.Handle(new ApplicationStartedEvent()); Subject.Handle(new ApplicationStartedEvent());
QueueAndWaitForExecution(commandModel); QueueAndWaitForExecution(commandModel, true);
VerifyEventPublished<CommandExecutedEvent>(); VerifyEventPublished<CommandExecutedEvent>();
} }

@ -65,19 +65,19 @@ namespace NzbDrone.App.Test
} }
[Test] [Test]
public void should_return_same_instance_of_singletons() public void should_return_same_instance_via_resolve_and_resolveall()
{ {
var first = _container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single(); var first = (DownloadMonitoringService)_container.Resolve<IHandle<TrackedDownloadsRemovedEvent>>();
var second = _container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single(); var second = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
first.Should().BeSameAs(second); first.Should().BeSameAs(second);
} }
[Test] [Test]
public void should_return_same_instance_of_singletons_by_different_same_interface() public void should_return_same_instance_of_singletons_by_same_interface()
{ {
var first = _container.ResolveAll<IHandle<AlbumGrabbedEvent>>().OfType<DownloadMonitoringService>().Single(); var first = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
var second = _container.ResolveAll<IHandle<AlbumGrabbedEvent>>().OfType<DownloadMonitoringService>().Single(); var second = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
first.Should().BeSameAs(second); first.Should().BeSameAs(second);
} }
@ -85,7 +85,7 @@ namespace NzbDrone.App.Test
[Test] [Test]
public void should_return_same_instance_of_singletons_by_different_interfaces() public void should_return_same_instance_of_singletons_by_different_interfaces()
{ {
var first = _container.ResolveAll<IHandle<AlbumGrabbedEvent>>().OfType<DownloadMonitoringService>().Single(); var first = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
var second = (DownloadMonitoringService)_container.Resolve<IExecute<CheckForFinishedDownloadCommand>>(); var second = (DownloadMonitoringService)_container.Resolve<IExecute<CheckForFinishedDownloadCommand>>();
first.Should().BeSameAs(second); first.Should().BeSameAs(second);

@ -1,4 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -11,16 +13,24 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
[Platform("Mono")] [Platform("Mono")]
public class FreeSpaceFixture : FreeSpaceFixtureBase<DiskProvider> public class FreeSpaceFixture : FreeSpaceFixtureBase<DiskProvider>
{ {
public FreeSpaceFixture()
{
MonoOnly();
}
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
Mocker.SetConstant<ISymbolicLinkResolver>(Mocker.Resolve<SymbolicLinkResolver>()); Mocker.SetConstant<IProcMountProvider>(new ProcMountProvider(TestLogger));
Mocker.SetConstant<IProcMountProvider>(Mocker.Resolve<ProcMountProvider>()); Mocker.GetMock<ISymbolicLinkResolver>()
.Setup(v => v.GetCompleteRealPath(It.IsAny<string>()))
.Returns<string>(s => s);
} }
public FreeSpaceFixture() [Test]
public void should_be_able_to_check_space_on_ramdrive()
{ {
MonoOnly(); Subject.GetAvailableSpace("/run/").Should().NotBe(0);
} }
} }
} }

@ -44,7 +44,7 @@ namespace NzbDrone.Test.Common
private static void RegisterConsoleLogger() private static void RegisterConsoleLogger()
{ {
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" }; var consoleTarget = new ConsoleTarget { Layout = "${date:format=HH\\:mm\\:ss.f} ${level}: ${message} ${exception}" };
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget)); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
} }

@ -1,4 +1,6 @@
using NUnit.Framework; using System.IO;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Test.DiskTests; using NzbDrone.Common.Test.DiskTests;
using NzbDrone.Windows.Disk; using NzbDrone.Windows.Disk;
@ -12,5 +14,28 @@ namespace NzbDrone.Windows.Test.DiskProviderTests
{ {
WindowsOnly(); WindowsOnly();
} }
[Test]
public void should_throw_if_drive_doesnt_exist()
{
// Find a drive that doesn't exist.
for (char driveletter = 'Z'; driveletter > 'D'; driveletter--)
{
if (new DriveInfo(driveletter.ToString()).IsReady)
continue;
Assert.Throws<DirectoryNotFoundException>(() => Subject.GetAvailableSpace(driveletter + @":\NOT_A_REAL_PATH\DOES_NOT_EXIST"));
return;
}
Assert.Inconclusive("No drive available for testing.");
}
[Test]
public void should_be_able_to_get_space_on_unc()
{
var result = Subject.GetAvailableSpace(@"\\localhost\c$\Windows");
result.Should().BeGreaterThan(0);
}
} }
} }

Loading…
Cancel
Save