mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Monitoring provider will no longer throw on Ensure priority.
Fix: Issue where an uncritical subsystem could crash the app.
This commit is contained in:
parent
83089457d8
commit
1787852360
@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
using FizzWare.NBuilder;
|
||||
@ -8,7 +9,6 @@
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Providers;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.App.Test
|
||||
{
|
||||
@ -19,17 +19,21 @@ public class MonitoringProviderTest : TestBase
|
||||
[Test]
|
||||
public void Ensure_priority_doesnt_fail_on_invalid_iis_proccess_id()
|
||||
{
|
||||
var processMock = Mocker.GetMock<ProcessProvider>();
|
||||
processMock.Setup(c => c.GetCurrentProcess())
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetCurrentProcess())
|
||||
.Returns(Builder<ProcessInfo>.CreateNew().With(c => c.Priority == ProcessPriorityClass.Normal).Build());
|
||||
|
||||
processMock.Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetProcessById(It.IsAny<int>())).Returns((ProcessInfo)null);
|
||||
|
||||
var subject = Mocker.Resolve<MonitoringProvider>();
|
||||
Mocker.Resolve<MonitoringProvider>().EnsurePriority(null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ensure_should_log_warn_exception_rather_than_throw()
|
||||
{
|
||||
Mocker.GetMock<ProcessProvider>().Setup(c => c.GetCurrentProcess()).Throws<InvalidOperationException>();
|
||||
Mocker.Resolve<MonitoringProvider>().EnsurePriority(null);
|
||||
|
||||
//Act
|
||||
subject.EnsurePriority(null);
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +46,9 @@
|
||||
<Reference Include="Ninject">
|
||||
<HintPath>..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
|
||||
|
@ -4,5 +4,6 @@
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="3.0.1.1" />
|
||||
<package id="Ninject" version="2.2.1.4" />
|
||||
<package id="NLog" version="2.0.0.2000" />
|
||||
<package id="NUnit" version="2.6.0.12054" />
|
||||
</packages>
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 894 B |
@ -44,7 +44,7 @@ public void Start()
|
||||
|
||||
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
|
||||
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
|
||||
|
||||
|
||||
_processPriorityCheckTimer = new Timer(EnsurePriority);
|
||||
_processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30));
|
||||
|
||||
@ -55,17 +55,24 @@ public void Start()
|
||||
|
||||
public virtual void EnsurePriority(object sender)
|
||||
{
|
||||
var currentProcess = _processProvider.GetCurrentProcess();
|
||||
if (currentProcess.Priority != ProcessPriorityClass.Normal)
|
||||
try
|
||||
{
|
||||
_processProvider.SetPriority(currentProcess.Id, ProcessPriorityClass.Normal);
|
||||
}
|
||||
var currentProcess = _processProvider.GetCurrentProcess();
|
||||
if (currentProcess.Priority != ProcessPriorityClass.Normal)
|
||||
{
|
||||
_processProvider.SetPriority(currentProcess.Id, ProcessPriorityClass.Normal);
|
||||
}
|
||||
|
||||
var iisProcess = _processProvider.GetProcessById(_iisProvider.IISProcessId);
|
||||
if (iisProcess != null && iisProcess.Priority != ProcessPriorityClass.Normal &&
|
||||
iisProcess.Priority != ProcessPriorityClass.AboveNormal)
|
||||
var iisProcess = _processProvider.GetProcessById(_iisProvider.IISProcessId);
|
||||
if (iisProcess != null && iisProcess.Priority != ProcessPriorityClass.Normal &&
|
||||
iisProcess.Priority != ProcessPriorityClass.AboveNormal)
|
||||
{
|
||||
_processProvider.SetPriority(iisProcess.Id, ProcessPriorityClass.Normal);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_processProvider.SetPriority(iisProcess.Id, ProcessPriorityClass.Normal);
|
||||
logger.WarnException("Unable to verify priority", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user