Fixed several failing/flaky mono unit tests

pull/3307/head
Taloth Saldono 6 years ago
parent be66a0520d
commit aacb8970f8

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

@ -3,6 +3,7 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Model; using NzbDrone.Common.Model;
@ -68,8 +69,10 @@ namespace NzbDrone.Common.Test
{ {
var process = StartDummyProcess(); var process = StartDummyProcess();
Thread.Sleep(500);
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should() Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
.BeTrue("excepted one dummy process to be already running"); .BeTrue("one running dummy process");
process.Kill(); process.Kill();
process.WaitForExit(); process.WaitForExit();
@ -133,6 +136,8 @@ namespace NzbDrone.Common.Test
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();

@ -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<EpisodeGrabbedEvent>>().OfType<DownloadMonitoringService>().Single(); var first = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
var second = _container.ResolveAll<IHandle<EpisodeGrabbedEvent>>().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<EpisodeGrabbedEvent>>().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,9 @@
using NUnit.Framework; using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Test.DiskTests; using NzbDrone.Common.Test.DiskTests;
using NzbDrone.Mono.Disk; using NzbDrone.Mono.Disk;
@ -12,5 +17,20 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
{ {
MonoOnly(); MonoOnly();
} }
[SetUp]
public void Setup()
{
Mocker.SetConstant<IProcMountProvider>(new ProcMountProvider(TestLogger));
Mocker.GetMock<ISymbolicLinkResolver>()
.Setup(v => v.GetCompleteRealPath(It.IsAny<string>()))
.Returns<string>(s => s);
}
[Test]
public void should_be_able_to_check_space_on_ramdrive()
{
Subject.GetAvailableSpace("/run/").Should().NotBe(0);
}
} }
} }

@ -13,7 +13,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo
[Test] [Test]
public void should_get_framework_version() public void should_get_framework_version()
{ {
Subject.Version.Major.Should().BeOneOf(4, 5); Subject.Version.Major.Should().BeOneOf(4, 5, 6);
if (Subject.Version.Major == 4) if (Subject.Version.Major == 4)
{ {
Subject.Version.Minor.Should().BeOneOf(0, 5, 6); Subject.Version.Minor.Should().BeOneOf(0, 5, 6);

@ -46,7 +46,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