mirror of
https://github.com/Sonarr/Sonarr
synced 2026-05-08 21:21:47 +02:00
Only reuse healthy waiting tracked downloads
This commit is contained in:
parent
c87c96ff1e
commit
7cfbc88fb8
2 changed files with 69 additions and 1 deletions
|
|
@ -175,6 +175,66 @@ public void should_reprocess_when_waiting_download_identity_changes()
|
|||
.Verify(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), null), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_reprocess_when_waiting_download_has_warning_status()
|
||||
{
|
||||
GivenTrackedDownloadCanBeMapped();
|
||||
|
||||
var client = CreateDownloadClient();
|
||||
var item = CreateDownloadItem(DownloadItemStatus.Queued);
|
||||
var updatedItem = CreateDownloadItem(DownloadItemStatus.Queued);
|
||||
updatedItem.RemainingSize = 250;
|
||||
|
||||
var trackedDownload = Subject.TrackDownload(client, item);
|
||||
trackedDownload.Warn("Temporary warning");
|
||||
|
||||
var refreshedTrackedDownload = Subject.TrackDownload(client, updatedItem);
|
||||
|
||||
refreshedTrackedDownload.Should().NotBeSameAs(trackedDownload);
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Verify(s => s.FindByDownloadId(It.IsAny<string>()), Times.Exactly(2));
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Verify(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), null), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_reprocess_when_waiting_download_is_not_mapped()
|
||||
{
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
.Returns(new List<EpisodeHistory>());
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), null))
|
||||
.Returns(new RemoteEpisode
|
||||
{
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
SeriesTitle = "TV Series",
|
||||
SeasonNumber = 1,
|
||||
EpisodeNumbers = new[] { 1 }
|
||||
}
|
||||
});
|
||||
|
||||
var client = CreateDownloadClient();
|
||||
var item = CreateDownloadItem(DownloadItemStatus.Queued);
|
||||
var updatedItem = CreateDownloadItem(DownloadItemStatus.Queued);
|
||||
updatedItem.RemainingSize = 250;
|
||||
|
||||
var trackedDownload = Subject.TrackDownload(client, item);
|
||||
var refreshedTrackedDownload = Subject.TrackDownload(client, updatedItem);
|
||||
|
||||
refreshedTrackedDownload.Should().NotBeSameAs(trackedDownload);
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Verify(s => s.FindByDownloadId(It.IsAny<string>()), Times.Exactly(2));
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Verify(s => s.Map(It.IsAny<ParsedEpisodeInfo>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<string>(), null), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_track_downloads_using_the_source_title_if_it_cannot_be_found_using_the_download_title()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -230,7 +230,8 @@ private static bool CanReuseTrackedDownload(TrackedDownload existingItem, Downlo
|
|||
}
|
||||
|
||||
return IsStableWaitingDownload(downloadItem) &&
|
||||
HasSameDownloadIdentity(existingItem.DownloadItem, downloadItem);
|
||||
HasSameDownloadIdentity(existingItem.DownloadItem, downloadItem) &&
|
||||
HasHealthyWaitingCache(existingItem);
|
||||
}
|
||||
|
||||
private static bool IsStableWaitingDownload(DownloadClientItem downloadItem)
|
||||
|
|
@ -239,6 +240,13 @@ private static bool IsStableWaitingDownload(DownloadClientItem downloadItem)
|
|||
downloadItem.Status == DownloadItemStatus.Paused;
|
||||
}
|
||||
|
||||
private static bool HasHealthyWaitingCache(TrackedDownload existingItem)
|
||||
{
|
||||
return existingItem.Status == TrackedDownloadStatus.Ok &&
|
||||
existingItem.RemoteEpisode?.Series != null &&
|
||||
existingItem.RemoteEpisode.Episodes?.Any() == true;
|
||||
}
|
||||
|
||||
private static bool HasSameDownloadIdentity(DownloadClientItem existingItem, DownloadClientItem downloadItem)
|
||||
{
|
||||
return existingItem.DownloadId == downloadItem.DownloadId &&
|
||||
|
|
|
|||
Loading…
Reference in a new issue