1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

When restarting after update if service start fails update app will fallback to console.

This commit is contained in:
kay.one 2013-06-14 08:21:12 -07:00
parent 44ff12eaaa
commit d0d95602c6
4 changed files with 78 additions and 13 deletions

View File

@ -9,10 +9,8 @@
namespace NzbDrone.Update.Test
{
[TestFixture]
public class UpdateProviderVerifyFixture : TestBase
public class InstallUpdateServiceFixture : TestBase<InstallUpdateService>
{
[SetUp]
public void Setup()
{
@ -25,7 +23,7 @@ public void Setup()
[TestCase(" ")]
public void update_should_throw_target_folder_is_blank(string target)
{
Assert.Throws<ArgumentException>(() => Mocker.Resolve<InstallUpdateService>().Start(target))
Assert.Throws<ArgumentException>(() => Subject.Start(target))
.Message.Should().StartWith("Target folder can not be null or empty");
}
@ -34,7 +32,7 @@ public void update_should_throw_if_target_folder_doesnt_exist()
{
string targetFolder = "c:\\NzbDrone\\";
Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<InstallUpdateService>().Start(targetFolder))
Assert.Throws<DirectoryNotFoundException>(() => Subject.Start(targetFolder))
.Message.Should().StartWith("Target folder doesn't exist");
}
@ -52,7 +50,7 @@ public void update_should_throw_if_update_folder_doesnt_exist()
.Setup(c => c.FolderExists(sandboxFolder))
.Returns(false);
Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<InstallUpdateService>().Start(targetFolder))
Assert.Throws<DirectoryNotFoundException>(() => Subject.Start(targetFolder))
.Message.Should().StartWith("Update folder doesn't exist");
}
}

View File

@ -85,8 +85,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="StartNzbDroneService.cs" />
<Compile Include="ProgramFixture.cs" />
<Compile Include="UpdateProviderVerifyFixture.cs" />
<Compile Include="InstallUpdateServiceFixture.cs" />
<Compile Include="UpdateProviderStartFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@ -0,0 +1,40 @@
using System;
using System.IO;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Test.Common;
using NzbDrone.Update.UpdateEngine;
namespace NzbDrone.Update.Test
{
[TestFixture]
public class StartNzbDroneServiceFixture : TestBase<StartNzbDrone>
{
[Test]
public void should_start_service_if_app_type_was_serivce()
{
string targetFolder = "c:\\NzbDrone\\";
Subject.Start(AppType.Service, targetFolder);
Mocker.GetMock<Common.IServiceProvider>().Verify(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME), Times.Once());
}
[Test]
public void should_start_console_if_app_type_was_serivce_but_start_failed_because_of_permissions()
{
string targetFolder = "c:\\NzbDrone\\";
Mocker.GetMock<Common.IServiceProvider>().Setup(c => c.Start(ServiceProvider.NZBDRONE_SERVICE_NAME)).Throws(new InvalidOperationException());
Subject.Start(AppType.Service, targetFolder);
Mocker.GetMock<IProcessProvider>().Verify(c => c.Start("c:\\NzbDrone\\NzbDrone.Console.exe"), Times.Once());
ExceptionVerification.ExpectedWarns(1);
}
}
}

View File

@ -1,6 +1,8 @@
using System;
using System.IO;
using NLog;
using NzbDrone.Common;
using IServiceProvider = NzbDrone.Common.IServiceProvider;
namespace NzbDrone.Update.UpdateEngine
{
@ -27,19 +29,43 @@ public void Start(AppType appType, string installationFolder)
_logger.Info("Starting NzbDrone");
if (appType == AppType.Service)
{
_logger.Info("Starting NzbDrone service");
_serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
try
{
StartService();
}
catch (InvalidOperationException e)
{
_logger.Warn("Couldn't start NzbDrone Service (Most likely due to permission issues). falling back to console.", e);
StartConsole(installationFolder);
}
}
else if (appType == AppType.Console)
{
_logger.Info("Starting NzbDrone with Console");
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.Console.exe"));
StartConsole(installationFolder);
}
else
{
_logger.Info("Starting NzbDrone without Console");
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.exe"));
StartWinform(installationFolder);
}
}
private void StartService()
{
_logger.Info("Starting NzbDrone service");
_serviceProvider.Start(ServiceProvider.NZBDRONE_SERVICE_NAME);
}
private void StartWinform(string installationFolder)
{
_logger.Info("Starting NzbDrone without Console");
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.exe"));
}
private void StartConsole(string installationFolder)
{
_logger.Info("Starting NzbDrone with Console");
_processProvider.Start(Path.Combine(installationFolder, "NzbDrone.Console.exe"));
}
}
}