Skip to content

Commit 4dcc015

Browse files
authored
Fixed: qBittorrent Ratio Limit Check
Closes Sonarr#7527
1 parent 1969e01 commit 4dcc015

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,30 @@ public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached
712712
item.CanMoveFiles.Should().BeTrue();
713713
}
714714

715+
[TestCase("pausedUP")]
716+
[TestCase("stoppedUP")]
717+
public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached_after_rounding_and_paused(string state)
718+
{
719+
GivenGlobalSeedLimits(1.0f);
720+
GivenCompletedTorrent(state, ratio: 1.1006066990976857f);
721+
722+
var item = Subject.GetItems().Single();
723+
item.CanBeRemoved.Should().BeTrue();
724+
item.CanMoveFiles.Should().BeTrue();
725+
}
726+
727+
[TestCase("pausedUP")]
728+
[TestCase("stoppedUP")]
729+
public void should_be_removable_and_should_allow_move_files_if_just_under_max_ratio_reached_after_rounding_and_paused(string state)
730+
{
731+
GivenGlobalSeedLimits(1.0f);
732+
GivenCompletedTorrent(state, ratio: 0.9999f);
733+
734+
var item = Subject.GetItems().Single();
735+
item.CanBeRemoved.Should().BeTrue();
736+
item.CanMoveFiles.Should().BeTrue();
737+
}
738+
715739
[TestCase("pausedUP")]
716740
[TestCase("stoppedUP")]
717741
public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_and_paused(string state)
@@ -724,6 +748,30 @@ public void should_be_removable_and_should_allow_move_files_if_overridden_max_ra
724748
item.CanMoveFiles.Should().BeTrue();
725749
}
726750

751+
[TestCase("pausedUP")]
752+
[TestCase("stoppedUP")]
753+
public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_after_rounding_and_paused(string state)
754+
{
755+
GivenGlobalSeedLimits(2.0f);
756+
GivenCompletedTorrent(state, ratio: 1.1006066990976857f, ratioLimit: 1.1f);
757+
758+
var item = Subject.GetItems().Single();
759+
item.CanBeRemoved.Should().BeTrue();
760+
item.CanMoveFiles.Should().BeTrue();
761+
}
762+
763+
[TestCase("pausedUP")]
764+
[TestCase("stoppedUP")]
765+
public void should_be_removable_and_should_allow_move_files_if_just_under_overridden_max_ratio_reached_after_rounding_and_paused(string state)
766+
{
767+
GivenGlobalSeedLimits(2.0f);
768+
GivenCompletedTorrent(state, ratio: 0.9999f, ratioLimit: 1.0f);
769+
770+
var item = Subject.GetItems().Single();
771+
item.CanBeRemoved.Should().BeTrue();
772+
item.CanMoveFiles.Should().BeTrue();
773+
}
774+
727775
[TestCase("pausedUP")]
728776
[TestCase("stoppedUP")]
729777
public void should_not_be_removable_if_overridden_max_ratio_not_reached_and_paused(string state)

src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,14 @@ protected bool HasReachedSeedLimit(QBittorrentTorrent torrent, QBittorrentPrefer
630630
{
631631
if (torrent.RatioLimit >= 0)
632632
{
633-
if (torrent.Ratio >= torrent.RatioLimit)
633+
if (torrent.RatioLimit - torrent.Ratio <= 0.001f)
634634
{
635635
return true;
636636
}
637637
}
638638
else if (torrent.RatioLimit == -2 && config.MaxRatioEnabled)
639639
{
640-
if (Math.Round(torrent.Ratio, 2) >= config.MaxRatio)
640+
if (config.MaxRatio - torrent.Ratio <= 0.001f)
641641
{
642642
return true;
643643
}

0 commit comments

Comments
 (0)