diff --git a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs index f293bcdbd..d653c84ac 100644 --- a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs @@ -110,6 +110,18 @@ namespace NzbDrone.Core.Test.Download .Verify(v => v.PublishEvent(It.Is(d => d.EpisodeIds.Count == count)), Times.Once()); } + private void VerifyRetryDownload() + { + Mocker.GetMock() + .Verify(v => v.RetryDownload(It.IsAny()), Times.Once()); + } + + private void VerifyNoRetryDownload() + { + Mocker.GetMock() + .Verify(v => v.RetryDownload(It.IsAny()), Times.Never()); + } + [Test] public void should_not_process_if_no_download_client_history() { @@ -314,6 +326,7 @@ namespace NzbDrone.Core.Test.Download Subject.Execute(new CheckForFinishedDownloadCommand()); VerifyFailedDownloads(); + VerifyNoRetryDownload(); } [Test] @@ -335,6 +348,31 @@ namespace NzbDrone.Core.Test.Download Subject.Execute(new CheckForFinishedDownloadCommand()); VerifyFailedDownloads(); + VerifyNoRetryDownload(); + } + + [Test] + public void should_not_retry_if_already_failed() + { + GivenFailedDownloadClientHistory(); + + var historyGrabbed = Builder.CreateListOfSize(1) + .Build() + .ToList(); + + historyGrabbed.First().Data.Add("downloadClient", "SabnzbdClient"); + historyGrabbed.First().Data.Add("downloadClientId", _failed.First().DownloadClientId); + historyGrabbed.First().Data.Add("ageHours", "1"); + + GivenGrabbedHistory(historyGrabbed); + GivenFailedHistory(historyGrabbed); + GivenGracePeriod(6); + GivenRetryLimit(1); + + Subject.Execute(new CheckForFinishedDownloadCommand()); + + VerifyNoFailedDownloads(); + VerifyNoRetryDownload(); } [Test] @@ -357,6 +395,7 @@ namespace NzbDrone.Core.Test.Download Subject.Execute(new CheckForFinishedDownloadCommand()); VerifyFailedDownloads(); + VerifyNoRetryDownload(); } [Test] @@ -380,6 +419,7 @@ namespace NzbDrone.Core.Test.Download Subject.Execute(new CheckForFinishedDownloadCommand()); VerifyNoFailedDownloads(); + VerifyRetryDownload(); ExceptionVerification.IgnoreWarns(); } diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index c104897bd..775f6f619 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -96,30 +96,31 @@ namespace NzbDrone.Core.Download return; } - //TODO: Make this more configurable (ignore failure reasons) to support changes and other failures that should be ignored - if (trackedDownload.DownloadItem.Message.Equals("Unpacking failed, write error or disk is full?", - StringComparison.InvariantCultureIgnoreCase)) - { - UpdateStatusMessage(trackedDownload, LogLevel.Error, "Download failed due to lack of disk space, not blacklisting."); - return; - } - - if (FailedDownloadForRecentRelease(downloadClient, trackedDownload, grabbedItems)) - { - _logger.Debug("[{0}] Recent release Failed, do not blacklist.", trackedDownload.DownloadItem.Title); - return; - } - - trackedDownload.State = TrackedDownloadState.DownloadFailed; - var failedItems = GetHistoryItems(failedHistory, trackedDownload.DownloadItem.DownloadClientId); if (failedItems.Any()) { + trackedDownload.State = TrackedDownloadState.DownloadFailed; UpdateStatusMessage(trackedDownload, LogLevel.Debug, "Already added to history as failed."); } else { + //TODO: Make this more configurable (ignore failure reasons) to support changes and other failures that should be ignored + if (trackedDownload.DownloadItem.Message.Equals("Unpacking failed, write error or disk is full?", + StringComparison.InvariantCultureIgnoreCase)) + { + UpdateStatusMessage(trackedDownload, LogLevel.Error, "Download failed due to lack of disk space, not blacklisting."); + return; + } + + if (FailedDownloadForRecentRelease(downloadClient, trackedDownload, grabbedItems)) + { + _logger.Debug("[{0}] Recent release Failed, do not blacklist.", trackedDownload.DownloadItem.Title); + return; + } + + trackedDownload.State = TrackedDownloadState.DownloadFailed; + PublishDownloadFailedEvent(grabbedItems, trackedDownload.DownloadItem.Message); } }