File tree Expand file tree Collapse file tree 4 files changed +107
-0
lines changed
Expand file tree Collapse file tree 4 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 1+ using NUnit . Framework ;
2+ using NzbDrone . Core . HealthCheck . Checks ;
3+ using NzbDrone . Core . Test . Framework ;
4+ using NzbDrone . Test . Common ;
5+ using static NzbDrone . Core . HealthCheck . Checks . MonoDebugCheck ;
6+
7+ namespace NzbDrone . Core . Test . HealthCheck . Checks
8+ {
9+ [ TestFixture ]
10+ public class MonoDebugFixture : CoreTest < MonoDebugCheck >
11+ {
12+ private void GivenHasStackFrame ( bool hasStackFrame )
13+ {
14+ Mocker . GetMock < StackFrameHelper > ( )
15+ . Setup ( f => f . HasStackFrameInfo ( ) )
16+ . Returns ( hasStackFrame ) ;
17+ }
18+
19+ [ Test ]
20+ public void should_return_ok_if_windows ( )
21+ {
22+ WindowsOnly ( ) ;
23+
24+ Subject . Check ( ) . ShouldBeOk ( ) ;
25+ }
26+
27+ [ Test ]
28+ public void should_return_ok_if_not_debug ( )
29+ {
30+ MonoOnly ( ) ;
31+
32+ GivenHasStackFrame ( false ) ;
33+
34+ Subject . Check ( ) . ShouldBeOk ( ) ;
35+ }
36+
37+ [ Test ]
38+ public void should_log_warning_if_not_debug ( )
39+ {
40+ MonoOnly ( ) ;
41+
42+ GivenHasStackFrame ( false ) ;
43+
44+ Subject . Check ( ) ;
45+
46+ ExceptionVerification . ExpectedWarns ( 1 ) ;
47+ }
48+
49+ [ Test ]
50+ public void should_return_ok_if_debug ( )
51+ {
52+ MonoOnly ( ) ;
53+
54+ GivenHasStackFrame ( true ) ;
55+
56+ Subject . Check ( ) . ShouldBeOk ( ) ;
57+ }
58+ }
59+ }
Original file line number Diff line number Diff line change 236236 <Compile Include =" HealthCheck\Checks\ImportMechanismCheckFixture.cs" />
237237 <Compile Include =" HealthCheck\Checks\IndexerSearchCheckFixture.cs" />
238238 <Compile Include =" HealthCheck\Checks\IndexerRssCheckFixture.cs" />
239+ <Compile Include =" HealthCheck\Checks\MonoDebugFixture.cs" />
239240 <Compile Include =" HealthCheck\Checks\MonoVersionCheckFixture.cs" />
240241 <Compile Include =" HealthCheck\Checks\IndexerStatusCheckFixture.cs" />
241242 <Compile Include =" HealthCheck\Checks\RootFolderCheckFixture.cs" />
Original file line number Diff line number Diff line change 1+ using System . Diagnostics ;
2+ using NLog ;
3+ using NzbDrone . Common . EnvironmentInfo ;
4+
5+ namespace NzbDrone . Core . HealthCheck . Checks
6+ {
7+ public class MonoDebugCheck : HealthCheckBase
8+ {
9+ private readonly Logger _logger ;
10+ private readonly StackFrameHelper _stackFrameHelper ;
11+
12+ public override bool CheckOnSchedule => false ;
13+
14+ public MonoDebugCheck ( Logger logger , StackFrameHelper stackFrameHelper )
15+ {
16+ _logger = logger ;
17+ _stackFrameHelper = stackFrameHelper ;
18+ }
19+
20+ public class StackFrameHelper
21+ {
22+ public virtual bool HasStackFrameInfo ( )
23+ {
24+ var stackTrace = new StackTrace ( ) ;
25+
26+ return stackTrace . FrameCount > 0 && stackTrace . GetFrame ( 0 ) . GetFileColumnNumber ( ) > 0 ;
27+ }
28+ }
29+
30+ public override HealthCheck Check ( )
31+ {
32+ if ( ! PlatformInfo . IsMono )
33+ {
34+ return new HealthCheck ( GetType ( ) ) ;
35+ }
36+
37+ if ( ! _stackFrameHelper . HasStackFrameInfo ( ) )
38+ {
39+ _logger . Warn ( "Mono is not running with --debug switch" ) ;
40+ return new HealthCheck ( GetType ( ) ) ;
41+ }
42+
43+ return new HealthCheck ( GetType ( ) ) ;
44+ }
45+ }
46+ }
Original file line number Diff line number Diff line change 577577 <Compile Include =" HealthCheck\Checks\DownloadClientCheck.cs" />
578578 <Compile Include =" HealthCheck\Checks\DownloadClientStatusCheck.cs" />
579579 <Compile Include =" HealthCheck\Checks\DeprecatedDroneFactoryCheck.cs" />
580+ <Compile Include =" HealthCheck\Checks\MonoDebugCheck.cs" />
580581 <Compile Include =" HealthCheck\Checks\MonoTlsCheck.cs" />
581582 <Compile Include =" HealthCheck\Checks\MountCheck.cs" />
582583 <Compile Include =" HealthCheck\Checks\DroneFactoryCheck.cs" />
You can’t perform that action at this time.
0 commit comments