From b0fb3692905c3a74568cf3a78cf0d35ae9656285 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 31 Mar 2018 21:51:41 -0400 Subject: [PATCH] Added: Check if mono is running with --debug arg https://github.com/Sonarr/Sonarr/commit/13a259b47313100b53dfacd4423107da19a2cf9d --- .../Checks/MonoDebugCheckFixture.cs | 59 +++++++++++++++++++ .../NzbDrone.Core.Test.csproj | 1 + .../HealthCheck/Checks/MonoDebugCheck.cs | 46 +++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 107 insertions(+) create mode 100644 src/NzbDrone.Core.Test/HealthCheck/Checks/MonoDebugCheckFixture.cs create mode 100644 src/NzbDrone.Core/HealthCheck/Checks/MonoDebugCheck.cs diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/MonoDebugCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/MonoDebugCheckFixture.cs new file mode 100644 index 000000000..d56ff463d --- /dev/null +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/MonoDebugCheckFixture.cs @@ -0,0 +1,59 @@ +using NUnit.Framework; +using NzbDrone.Core.HealthCheck.Checks; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; +using static NzbDrone.Core.HealthCheck.Checks.MonoDebugCheck; + +namespace NzbDrone.Core.Test.HealthCheck.Checks +{ + [TestFixture] + public class MonoDebugCheckFixture : CoreTest + { + private void GivenHasStackFrame(bool hasStackFrame) + { + Mocker.GetMock() + .Setup(f => f.HasStackFrameInfo()) + .Returns(hasStackFrame); + } + + [Test] + public void should_return_ok_if_windows() + { + WindowsOnly(); + + Subject.Check().ShouldBeOk(); + } + + [Test] + public void should_return_ok_if_not_debug() + { + MonoOnly(); + + GivenHasStackFrame(false); + + Subject.Check().ShouldBeOk(); + } + + [Test] + public void should_log_warning_if_not_debug() + { + MonoOnly(); + + GivenHasStackFrame(false); + + Subject.Check(); + + ExceptionVerification.ExpectedWarns(1); + } + + [Test] + public void should_return_ok_if_debug() + { + MonoOnly(); + + GivenHasStackFrame(true); + + Subject.Check().ShouldBeOk(); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index e01f3dc9c..19145520d 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -210,6 +210,7 @@ + diff --git a/src/NzbDrone.Core/HealthCheck/Checks/MonoDebugCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/MonoDebugCheck.cs new file mode 100644 index 000000000..30cdb4085 --- /dev/null +++ b/src/NzbDrone.Core/HealthCheck/Checks/MonoDebugCheck.cs @@ -0,0 +1,46 @@ +using System.Diagnostics; +using NLog; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Core.HealthCheck.Checks +{ + public class MonoDebugCheck : HealthCheckBase + { + private readonly Logger _logger; + private readonly StackFrameHelper _stackFrameHelper; + + public override bool CheckOnSchedule => false; + + public MonoDebugCheck(Logger logger, StackFrameHelper stackFrameHelper) + { + _logger = logger; + _stackFrameHelper = stackFrameHelper; + } + + public class StackFrameHelper + { + public virtual bool HasStackFrameInfo() + { + var stackTrace = new StackTrace(); + + return stackTrace.FrameCount > 0 && stackTrace.GetFrame(0).GetFileColumnNumber() > 0; + } + } + + public override HealthCheck Check() + { + if (!PlatformInfo.IsMono) + { + return new HealthCheck(GetType()); + } + + if (!_stackFrameHelper.HasStackFrameInfo()) + { + _logger.Warn("Mono is not running with --debug switch"); + return new HealthCheck(GetType()); + } + + return new HealthCheck(GetType()); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index ac9306487..6bc7201a1 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -466,6 +466,7 @@ +