From 01d3decf7e76f747ab4ff93e92e4b11d1c968436 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 14 Mar 2014 03:15:30 -0700 Subject: [PATCH] Added Mono version health check --- .../DiskProviderTests/FreeSpaceFixtureBase.cs | 2 +- .../EnsureTest/PathExtensionFixture.cs | 2 +- .../PathExtensionFixture.cs | 4 +- .../Checks/MonoVersionCheckFixture.cs | 66 +++++++++++++++++++ .../NotUnpackingSpecificationFixture.cs | 2 +- .../MediaFiles/MediaFileServiceTest.cs | 2 +- .../NzbDrone.Core.Test.csproj | 3 +- .../HealthCheck/Checks/MonoVersionnCheck.cs | 49 ++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../DiskProviderTests/DiskProviderFixture.cs | 2 +- .../DiskProviderTests/FreeSpaceFixture.cs | 2 +- src/NzbDrone.Test.Common/TestBase.cs | 2 +- 12 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 src/NzbDrone.Core.Test/HealthCheck/Checks/MonoVersionCheckFixture.cs create mode 100644 src/NzbDrone.Core/HealthCheck/Checks/MonoVersionnCheck.cs diff --git a/src/NzbDrone.Common.Test/DiskProviderTests/FreeSpaceFixtureBase.cs b/src/NzbDrone.Common.Test/DiskProviderTests/FreeSpaceFixtureBase.cs index 4917c4457..f63942a11 100644 --- a/src/NzbDrone.Common.Test/DiskProviderTests/FreeSpaceFixtureBase.cs +++ b/src/NzbDrone.Common.Test/DiskProviderTests/FreeSpaceFixtureBase.cs @@ -36,7 +36,7 @@ public void should_get_free_space_for_drive_that_doesnt_exist() [Test] public void should_be_able_to_check_space_on_ramdrive() { - LinuxOnly(); + MonoOnly(); Subject.GetAvailableSpace("/run/").Should().NotBe(0); } diff --git a/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs index 04562a119..3388df9ad 100644 --- a/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs @@ -19,7 +19,7 @@ public void EnsureWindowsPath(string path) [TestCase(@"/var/user/file with, comma.mkv")] public void EnsureLinuxPath(string path) { - LinuxOnly(); + MonoOnly(); Ensure.That(path, () => path).IsValidPath(); } } diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index fbc2fb6b6..8c75708e2 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -50,7 +50,7 @@ public void Clean_Path_Windows(string dirty, string clean) [TestCase(@"//CAPITAL//lower// ", @"/CAPITAL/lower")] public void Clean_Path_Linux(string dirty, string clean) { - LinuxOnly(); + MonoOnly(); var result = dirty.CleanFilePath(); result.Should().Be(clean); @@ -139,7 +139,7 @@ public void get_actual_casing_should_return_actual_casing_for_local_dir_in_windo [Test] public void get_actual_casing_should_return_original_value_in_linux() { - LinuxOnly(); + MonoOnly(); var path = Directory.GetCurrentDirectory(); path.GetActualCasing().Should().Be(path); path.GetActualCasing().Should().Be(path); diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/MonoVersionCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/MonoVersionCheckFixture.cs new file mode 100644 index 000000000..02b06ad81 --- /dev/null +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/MonoVersionCheckFixture.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Processes; +using NzbDrone.Core.HealthCheck.Checks; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.HealthCheck.Checks +{ + [TestFixture] + public class MonoVersionCheckFixture : CoreTest + { + [SetUp] + public void Setup() + { + MonoOnly(); + } + + private void GivenOutput(string version) + { + Mocker.GetMock() + .Setup(s => s.StartAndCapture("mono", "--version")) + .Returns(new ProcessOutput + { + Standard = new List + { + String.Format("Mono JIT compiler version {0} (Debian {0}-8)", version), + "Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com" + } + }); + } + + [Test] + public void should_return_warning_when_mono_3_0() + { + GivenOutput("3.0.0.1"); + + Subject.Check().ShouldBeWarning(); + } + + [Test] + public void should_return_warning_when_mono_2_10_8() + { + GivenOutput("2.10.8.1"); + + Subject.Check().ShouldBeWarning(); + } + + [Test] + public void should_return_null_when_mono_3_2() + { + GivenOutput("3.2.0.1"); + + Subject.Check().Should().BeNull(); + } + + [Test] + public void should_return_null_when_mono_4_0() + { + GivenOutput("4.0.0.0"); + + Subject.Check().Should().BeNull(); + } + } +} diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecificationFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecificationFixture.cs index 0f4019163..155420917 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Specifications/NotUnpackingSpecificationFixture.cs @@ -75,7 +75,7 @@ public void should_return_false_if_in_working_folder_and_last_write_time_was_rec [Test] public void should_return_false_if_unopacking_on_linux() { - LinuxOnly(); + MonoOnly(); GivenInWorkingFolder(); GivenLastWriteTimeUtc(DateTime.UtcNow.AddDays(-5)); diff --git a/src/NzbDrone.Core.Test/MediaFiles/MediaFileServiceTest.cs b/src/NzbDrone.Core.Test/MediaFiles/MediaFileServiceTest.cs index 2135e773a..ea567a509 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MediaFileServiceTest.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MediaFileServiceTest.cs @@ -108,7 +108,7 @@ public void filter_should_return_none_existing_files_ignoring_case() [Test] public void filter_should_return_none_existing_files_not_ignoring_case() { - LinuxOnly(); + MonoOnly(); var files = new List() { diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index b21c4cfd2..dda23aeb2 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -125,10 +125,11 @@ + - + diff --git a/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionnCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionnCheck.cs new file mode 100644 index 000000000..867e9d458 --- /dev/null +++ b/src/NzbDrone.Core/HealthCheck/Checks/MonoVersionnCheck.cs @@ -0,0 +1,49 @@ +using System; +using System.Text.RegularExpressions; +using NLog; +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Processes; + +namespace NzbDrone.Core.HealthCheck.Checks +{ + public class MonoVersionnCheck : IProvideHealthCheck + { + private readonly IProcessProvider _processProvider; + private readonly Logger _logger; + private static readonly Regex VersionRegex = new Regex(@"(?<=\W)(?\d+\.\d+\.\d+\.\d+)(?=\W)", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + public MonoVersionnCheck(IProcessProvider processProvider, Logger logger) + { + _processProvider = processProvider; + _logger = logger; + } + + public HealthCheck Check() + { + if (!OsInfo.IsMono) + { + return null; + } + + var output = _processProvider.StartAndCapture("mono", "--version"); + + foreach (var line in output.Standard) + { + var versionMatch = VersionRegex.Match(line); + + if (versionMatch.Success) + { + var version = new Version(versionMatch.Groups["version"].Value); + + if (version >= new Version(3, 2)) + { + _logger.Debug("mono version is 3.2 or better: {0}", version.ToString()); + return null; + } + } + } + + return new HealthCheck(HealthCheckResultType.Warning, "mono version is less than 3.2, upgrade for improved stability"); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index c2cf3f68b..258c9d773 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -268,6 +268,7 @@ + diff --git a/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs b/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs index aac55c5df..dffd16153 100644 --- a/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs +++ b/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs @@ -8,7 +8,7 @@ public class DiskProviderFixture : DiskProviderFixtureBase { public DiskProviderFixture() { - LinuxOnly(); + MonoOnly(); } } } diff --git a/src/NzbDrone.Mono.Test/DiskProviderTests/FreeSpaceFixture.cs b/src/NzbDrone.Mono.Test/DiskProviderTests/FreeSpaceFixture.cs index 247a0801d..109fb4825 100644 --- a/src/NzbDrone.Mono.Test/DiskProviderTests/FreeSpaceFixture.cs +++ b/src/NzbDrone.Mono.Test/DiskProviderTests/FreeSpaceFixture.cs @@ -8,7 +8,7 @@ public class FreeSpaceFixture : FreeSpaceFixtureBase { public FreeSpaceFixture() { - LinuxOnly(); + MonoOnly(); } } } diff --git a/src/NzbDrone.Test.Common/TestBase.cs b/src/NzbDrone.Test.Common/TestBase.cs index c42fca8a9..5809a8816 100644 --- a/src/NzbDrone.Test.Common/TestBase.cs +++ b/src/NzbDrone.Test.Common/TestBase.cs @@ -131,7 +131,7 @@ protected void WindowsOnly() } - protected void LinuxOnly() + protected void MonoOnly() { if (!OsInfo.IsMono) {