mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-21 22:04:31 -04:00
Fixed: Transmission seeding idle time handling
This commit is contained in:
+137
-3
@@ -42,8 +42,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
|
||||
var item = Subject.GetItems().Single();
|
||||
VerifyCompleted(item);
|
||||
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeTrue();
|
||||
item.CanBeRemoved.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -175,7 +175,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
|
||||
item.Status.Should().Be(expectedItemStatus);
|
||||
}
|
||||
|
||||
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, true)]
|
||||
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, false)]
|
||||
[TestCase(TransmissionTorrentStatus.CheckWait, DownloadItemStatus.Downloading, false)]
|
||||
[TestCase(TransmissionTorrentStatus.Check, DownloadItemStatus.Downloading, false)]
|
||||
[TestCase(TransmissionTorrentStatus.Queued, DownloadItemStatus.Completed, false)]
|
||||
@@ -283,5 +283,139 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
|
||||
var item = Subject.GetItems().Single();
|
||||
item.RemainingTime.Should().NotHaveValue();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_reached_and_not_stopped()
|
||||
{
|
||||
GivenGlobalSeedLimits(1.0);
|
||||
PrepareClientToReturnCompletedItem(false, ratio: 1.0);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_removable_and_should_not_allow_move_files_if_max_ratio_is_not_set()
|
||||
{
|
||||
GivenGlobalSeedLimits();
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 1.0);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached_and_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(1.0);
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 1.0);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_and_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(2.0);
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 1.0, ratioLimit: 0.8);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_removable_if_overridden_max_ratio_not_reached_and_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(0.2);
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 0.5, ratioLimit: 0.8);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_not_be_removable_and_should_not_allow_move_files_if_max_idletime_reached_and_not_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(null, 20);
|
||||
PrepareClientToReturnCompletedItem(false, ratio: 2.0, seedingTime: 30);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_removable_and_should_allow_move_files_if_max_idletime_reached_and_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(null, 20);
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 2.0, seedingTime: 20);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_removable_and_should_allow_move_files_if_overridden_max_idletime_reached_and_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(null, 40);
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 2.0, seedingTime: 20, idleLimit: 10);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_removable_and_should_not_allow_move_files_if_overridden_max_idletime_reached_and_not_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(null, 40);
|
||||
PrepareClientToReturnCompletedItem(false, ratio: 2.0, seedingTime: 20, idleLimit: 10);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_removable_if_overridden_max_idletime_not_reached_and_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(null, 20);
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 2.0, seedingTime: 30, idleLimit: 40);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_removable_if_max_idletime_reached_but_ratio_not_and_not_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(2.0, 20);
|
||||
PrepareClientToReturnCompletedItem(false, ratio: 1.0, seedingTime: 30);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_removable_and_should_allow_move_files_if_max_idletime_configured_and_paused()
|
||||
{
|
||||
GivenGlobalSeedLimits(2.0, 20);
|
||||
PrepareClientToReturnCompletedItem(true, ratio: 1.0, seedingTime: 30);
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+54
-4
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.Transmission;
|
||||
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
||||
@@ -72,11 +73,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
|
||||
{
|
||||
HashString = "HASH",
|
||||
IsFinished = true,
|
||||
Status = TransmissionTorrentStatus.Stopped,
|
||||
Status = TransmissionTorrentStatus.Seeding,
|
||||
Name = _title,
|
||||
TotalSize = 1000,
|
||||
LeftUntilDone = 0,
|
||||
DownloadDir = "somepath"
|
||||
DownloadDir = "somepath",
|
||||
DownloadedEver = 1000,
|
||||
UploadedEver = 900
|
||||
};
|
||||
|
||||
_magnet = new TransmissionTorrent
|
||||
@@ -106,7 +109,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
|
||||
|
||||
Mocker.GetMock<ITransmissionProxy>()
|
||||
.Setup(v => v.GetConfig(It.IsAny<TransmissionSettings>()))
|
||||
.Returns(_transmissionConfigItems);
|
||||
.Returns(() => Json.Deserialize<TransmissionConfig>(_transmissionConfigItems.ToJson()));
|
||||
|
||||
}
|
||||
|
||||
@@ -178,8 +181,40 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
|
||||
});
|
||||
}
|
||||
|
||||
protected void PrepareClientToReturnCompletedItem()
|
||||
protected void PrepareClientToReturnCompletedItem(bool stopped = false, double ratio = 0.9, int seedingTime = 60, double? ratioLimit = null, int? idleLimit = null)
|
||||
{
|
||||
if (stopped)
|
||||
_completed.Status = TransmissionTorrentStatus.Stopped;
|
||||
_completed.UploadedEver = (int)(_completed.DownloadedEver * ratio);
|
||||
_completed.SecondsSeeding = seedingTime * 60;
|
||||
|
||||
if (ratioLimit.HasValue)
|
||||
{
|
||||
if (double.IsPositiveInfinity(ratioLimit.Value))
|
||||
{
|
||||
_completed.SeedRatioMode = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_completed.SeedRatioMode = 1;
|
||||
_completed.SeedRatioLimit = ratioLimit.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (idleLimit.HasValue)
|
||||
{
|
||||
if (double.IsPositiveInfinity(idleLimit.Value))
|
||||
{
|
||||
_completed.SeedIdleMode = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_completed.SeedIdleMode = 1;
|
||||
_completed.SeedIdleLimit = idleLimit.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GivenTorrents(new List<TransmissionTorrent>
|
||||
{
|
||||
_completed
|
||||
@@ -193,5 +228,20 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.TransmissionTests
|
||||
_magnet
|
||||
});
|
||||
}
|
||||
|
||||
protected void GivenGlobalSeedLimits(double? ratioLimit = null, int? idleLimit = null)
|
||||
{
|
||||
_transmissionConfigItems["seedRatioLimited"] = ratioLimit.HasValue;
|
||||
if (ratioLimit.HasValue)
|
||||
{
|
||||
_transmissionConfigItems["seedRatioLimit"] = ratioLimit.Value;
|
||||
}
|
||||
|
||||
_transmissionConfigItems["idle-seeding-limit-enabled"] = idleLimit.HasValue;
|
||||
if (idleLimit.HasValue)
|
||||
{
|
||||
_transmissionConfigItems["idle-seeding-limit"] = idleLimit.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
|
||||
[Test]
|
||||
public void completed_download_should_have_required_properties()
|
||||
{
|
||||
PrepareClientToReturnCompletedItem();
|
||||
PrepareClientToReturnCompletedItem(true, ratioLimit: 0.5);
|
||||
var item = Subject.GetItems().Single();
|
||||
VerifyCompleted(item);
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.VuzeTests
|
||||
item.Status.Should().Be(expectedItemStatus);
|
||||
}
|
||||
|
||||
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, true)]
|
||||
[TestCase(TransmissionTorrentStatus.Stopped, DownloadItemStatus.Completed, false)]
|
||||
[TestCase(TransmissionTorrentStatus.CheckWait, DownloadItemStatus.Downloading, false)]
|
||||
[TestCase(TransmissionTorrentStatus.Check, DownloadItemStatus.Downloading, false)]
|
||||
[TestCase(TransmissionTorrentStatus.Queued, DownloadItemStatus.Queued, false)]
|
||||
|
||||
Reference in New Issue
Block a user