Fixed several failing/flaky mono unit tests

This commit is contained in:
Taloth Saldono 2019-09-12 14:44:22 +02:00
parent be66a0520d
commit aacb8970f8
9 changed files with 66 additions and 51 deletions

View File

@ -25,13 +25,6 @@ namespace NzbDrone.Common.Test.DiskTests
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]
public void should_return_free_disk_space()
{
@ -39,33 +32,6 @@ namespace NzbDrone.Common.Test.DiskTests
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]
public void should_be_able_to_get_space_on_folder_that_doesnt_exist()
{

View File

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

View File

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

View File

@ -71,9 +71,9 @@ namespace NzbDrone.Core.Test.Messaging.Commands
_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))
@ -141,7 +141,7 @@ namespace NzbDrone.Core.Test.Messaging.Commands
Subject.Handle(new ApplicationStartedEvent());
QueueAndWaitForExecution(commandModel);
QueueAndWaitForExecution(commandModel, true);
VerifyEventPublished<CommandExecutedEvent>();
@ -160,7 +160,7 @@ namespace NzbDrone.Core.Test.Messaging.Commands
Subject.Handle(new ApplicationStartedEvent());
QueueAndWaitForExecution(commandModel);
QueueAndWaitForExecution(commandModel, true);
VerifyEventPublished<CommandExecutedEvent>();
}

View File

@ -65,19 +65,19 @@ namespace NzbDrone.App.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 second = _container.ResolveAll<IHandle<ApplicationShutdownRequested>>().OfType<Scheduler>().Single();
var first = (DownloadMonitoringService)_container.Resolve<IHandle<TrackedDownloadsRemovedEvent>>();
var second = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
first.Should().BeSameAs(second);
}
[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 second = _container.ResolveAll<IHandle<EpisodeGrabbedEvent>>().OfType<DownloadMonitoringService>().Single();
var first = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
var second = _container.ResolveAll<IHandle<TrackedDownloadsRemovedEvent>>().OfType<DownloadMonitoringService>().Single();
first.Should().BeSameAs(second);
}
@ -85,7 +85,7 @@ namespace NzbDrone.App.Test
[Test]
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>>();
first.Should().BeSameAs(second);

View File

@ -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.Mono.Disk;
@ -12,5 +17,20 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
{
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);
}
}
}

View File

@ -13,7 +13,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo
[Test]
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)
{
Subject.Version.Minor.Should().BeOneOf(0, 5, 6);

View File

@ -46,7 +46,7 @@ namespace NzbDrone.Test.Common
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.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
}

View File

@ -1,4 +1,6 @@
using NUnit.Framework;
using System.IO;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Test.DiskTests;
using NzbDrone.Windows.Disk;
@ -12,5 +14,28 @@ namespace NzbDrone.Windows.Test.DiskProviderTests
{
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);
}
}
}