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