|
|
|
@ -12,6 +12,7 @@ using NzbDrone.Core.DecisionEngine;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
|
|
|
@ -121,7 +122,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_order_by_smallest_rounded_to_200mb_then_age()
|
|
|
|
|
public void should_order_by_age_then_largest_rounded_to_200mb()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisodeSd = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.SDTV), size: 100.Megabytes(), age: 1);
|
|
|
|
|
var remoteEpisodeHdSmallOld = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p), size: 1200.Megabytes(), age: 1000);
|
|
|
|
@ -135,7 +136,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisodeHdLargeYoung));
|
|
|
|
|
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
qualifiedReports.First().RemoteEpisode.Should().Be(remoteEpisodeSmallYoung);
|
|
|
|
|
qualifiedReports.First().RemoteEpisode.Should().Be(remoteEpisodeHdLargeYoung);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -199,5 +200,153 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
qualifiedReports.First().RemoteEpisode.Release.DownloadProtocol.Should().Be(DownloadProtocol.Torrent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_prefer_season_pack_above_single_episode()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1), GivenEpisode(2) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
|
|
|
|
|
remoteEpisode1.ParsedEpisodeInfo.FullSeason = true;
|
|
|
|
|
|
|
|
|
|
var decisions = new List<DownloadDecision>();
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode1));
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode2));
|
|
|
|
|
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
qualifiedReports.First().RemoteEpisode.ParsedEpisodeInfo.FullSeason.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_prefer_releases_with_more_seeders()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
|
|
|
|
|
var torrentInfo1 = new TorrentInfo();
|
|
|
|
|
torrentInfo1.PublishDate = DateTime.Now;
|
|
|
|
|
torrentInfo1.Size = 0;
|
|
|
|
|
torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent;
|
|
|
|
|
torrentInfo1.Seeders = 10;
|
|
|
|
|
|
|
|
|
|
var torrentInfo2 = torrentInfo1.JsonClone();
|
|
|
|
|
torrentInfo2.Seeders = 100;
|
|
|
|
|
|
|
|
|
|
remoteEpisode1.Release = torrentInfo1;
|
|
|
|
|
remoteEpisode2.Release = torrentInfo2;
|
|
|
|
|
|
|
|
|
|
var decisions = new List<DownloadDecision>();
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode1));
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode2));
|
|
|
|
|
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
((TorrentInfo) qualifiedReports.First().RemoteEpisode.Release).Seeders.Should().Be(torrentInfo2.Seeders);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_prefer_releases_with_more_peers_given_equal_number_of_seeds()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
|
|
|
|
|
var torrentInfo1 = new TorrentInfo();
|
|
|
|
|
torrentInfo1.PublishDate = DateTime.Now;
|
|
|
|
|
torrentInfo1.Size = 0;
|
|
|
|
|
torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent;
|
|
|
|
|
torrentInfo1.Seeders = 10;
|
|
|
|
|
torrentInfo1.Peers = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var torrentInfo2 = torrentInfo1.JsonClone();
|
|
|
|
|
torrentInfo2.Peers = 100;
|
|
|
|
|
|
|
|
|
|
remoteEpisode1.Release = torrentInfo1;
|
|
|
|
|
remoteEpisode2.Release = torrentInfo2;
|
|
|
|
|
|
|
|
|
|
var decisions = new List<DownloadDecision>();
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode1));
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode2));
|
|
|
|
|
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
((TorrentInfo)qualifiedReports.First().RemoteEpisode.Release).Peers.Should().Be(torrentInfo2.Peers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_prefer_releases_with_more_peers_no_seeds()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
|
|
|
|
|
var torrentInfo1 = new TorrentInfo();
|
|
|
|
|
torrentInfo1.PublishDate = DateTime.Now;
|
|
|
|
|
torrentInfo1.Size = 0;
|
|
|
|
|
torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent;
|
|
|
|
|
torrentInfo1.Seeders = 0;
|
|
|
|
|
torrentInfo1.Peers = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var torrentInfo2 = torrentInfo1.JsonClone();
|
|
|
|
|
torrentInfo2.Seeders = 0;
|
|
|
|
|
torrentInfo2.Peers = 100;
|
|
|
|
|
|
|
|
|
|
remoteEpisode1.Release = torrentInfo1;
|
|
|
|
|
remoteEpisode2.Release = torrentInfo2;
|
|
|
|
|
|
|
|
|
|
var decisions = new List<DownloadDecision>();
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode1));
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode2));
|
|
|
|
|
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
((TorrentInfo)qualifiedReports.First().RemoteEpisode.Release).Peers.Should().Be(torrentInfo2.Peers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_prefer_first_release_if_peers_and_size_are_too_similar()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
|
|
|
|
|
var torrentInfo1 = new TorrentInfo();
|
|
|
|
|
torrentInfo1.PublishDate = DateTime.Now;
|
|
|
|
|
torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent;
|
|
|
|
|
torrentInfo1.Seeders = 1000;
|
|
|
|
|
torrentInfo1.Peers = 10;
|
|
|
|
|
torrentInfo1.Size = 200.Megabytes();
|
|
|
|
|
|
|
|
|
|
var torrentInfo2 = torrentInfo1.JsonClone();
|
|
|
|
|
torrentInfo2.Seeders = 1100;
|
|
|
|
|
torrentInfo2.Peers = 10;
|
|
|
|
|
torrentInfo1.Size = 250.Megabytes();
|
|
|
|
|
|
|
|
|
|
remoteEpisode1.Release = torrentInfo1;
|
|
|
|
|
remoteEpisode2.Release = torrentInfo2;
|
|
|
|
|
|
|
|
|
|
var decisions = new List<DownloadDecision>();
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode1));
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode2));
|
|
|
|
|
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
((TorrentInfo) qualifiedReports.First().RemoteEpisode.Release).Should().Be(torrentInfo1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_prefer_first_release_if_age_and_size_are_too_similar()
|
|
|
|
|
{
|
|
|
|
|
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
|
|
|
|
|
|
|
|
|
remoteEpisode1.Release.PublishDate = DateTime.UtcNow.AddDays(-100);
|
|
|
|
|
remoteEpisode1.Release.Size = 200.Megabytes();
|
|
|
|
|
|
|
|
|
|
remoteEpisode2.Release.PublishDate = DateTime.UtcNow.AddDays(-150);
|
|
|
|
|
remoteEpisode2.Release.Size = 250.Megabytes();
|
|
|
|
|
|
|
|
|
|
var decisions = new List<DownloadDecision>();
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode1));
|
|
|
|
|
decisions.Add(new DownloadDecision(remoteEpisode2));
|
|
|
|
|
|
|
|
|
|
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
|
|
|
|
qualifiedReports.First().RemoteEpisode.Release.Should().Be(remoteEpisode1.Release);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|