From 6d12a8575627cf234e02fb0f17d11fa745237502 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 29 Apr 2013 20:43:05 -0700 Subject: [PATCH] single broken doesnt break the whole decision process --- .../AllowedDownloadSpecificationFixture.cs | 30 +++++++++++++--- .../DecisionEngine/DownloadDecisionMaker.cs | 35 +++++++++++++------ NzbDrone.Test.Common/LoggingTest.cs | 2 -- .../NzbDrone.Test.Common.csproj | 1 + 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/NzbDrone.Core.Test/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs index 5b3e6fc71..6fcd045ea 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/AllowedDownloadSpecificationFixture.cs @@ -8,6 +8,7 @@ using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.DecisionEngineTests { @@ -159,7 +160,30 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] - public void should_return_unknow_series_rejectio_if_series_is_unknow() + public void broken_report_shouldnt_blowup_the_process() + { + GivenSpecifications(_pass1); + + Mocker.GetMock().Setup(c => c.Map(It.IsAny())) + .Throws(); + + _reports = new List + { + new ReportInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"}, + new ReportInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"}, + new ReportInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"} + }; + + Subject.GetRssDecision(_reports); + + Mocker.GetMock().Verify(c => c.Map(It.IsAny()), Times.Exactly(_reports.Count)); + + ExceptionVerification.ExpectedErrors(3); + } + + + [Test] + public void should_return_unknown_series_rejection_if_series_is_unknow() { GivenSpecifications(_pass1, _pass2, _pass3); @@ -170,8 +194,6 @@ namespace NzbDrone.Core.Test.DecisionEngineTests result.Should().HaveCount(1); } - - - } + } \ No newline at end of file diff --git a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 6300c6925..eaac8b7ab 100644 --- a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -42,23 +42,38 @@ namespace NzbDrone.Core.DecisionEngine { foreach (var report in reports) { - var parsedEpisodeInfo = Parser.Parser.ParseTitle(report.Title); + DownloadDecision decision = null; - if (parsedEpisodeInfo != null) + try { - var remoteEpisode = _parsingService.Map(parsedEpisodeInfo); - remoteEpisode.Report = report; + var parsedEpisodeInfo = Parser.Parser.ParseTitle(report.Title); - if (remoteEpisode.Series != null) + if (parsedEpisodeInfo != null) { - yield return GetDecisionForReport(remoteEpisode, searchDefinition); - } - else - { - yield return new DownloadDecision(remoteEpisode, "Unknown Series"); + var remoteEpisode = _parsingService.Map(parsedEpisodeInfo); + remoteEpisode.Report = report; + + if (remoteEpisode.Series != null) + { + decision = GetDecisionForReport(remoteEpisode, searchDefinition); + } + else + { + decision = new DownloadDecision(remoteEpisode, "Unknown Series"); + } } } + catch (Exception e) + { + _logger.ErrorException("Couldn't process report.", e); + } + + if (decision != null) + { + yield return decision; + } } + } private DownloadDecision GetDecisionForReport(RemoteEpisode remoteEpisode, SearchDefinitionBase searchDefinition = null) diff --git a/NzbDrone.Test.Common/LoggingTest.cs b/NzbDrone.Test.Common/LoggingTest.cs index 846a1e845..d3873a6ad 100644 --- a/NzbDrone.Test.Common/LoggingTest.cs +++ b/NzbDrone.Test.Common/LoggingTest.cs @@ -2,13 +2,11 @@ using NLog; using NLog.Config; using NLog.Targets; using NUnit.Framework; -using NzbDrone.Common; namespace NzbDrone.Test.Common { public abstract class LoggingTest { - protected Logger TestLogger = LogManager.GetLogger("TestLogger"); protected static void InitLogging() diff --git a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj index cb63cc806..45b364f23 100644 --- a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj +++ b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj @@ -97,6 +97,7 @@ +