From 5f03e7142a24a73b14ad9b7aa059f14d87e5ffa8 Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Sun, 5 Jan 2025 02:56:49 +0100 Subject: [PATCH] Fixed: qBittorrent Ratio Limit Check (cherry picked from commit 4dcc015fb19ceb57d2e8f4985c5137e765829d1c) --- .../QBittorrentTests/QBittorrentFixture.cs | 48 +++++++++++++++++++ .../Clients/QBittorrent/QBittorrent.cs | 4 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index ef7161ef5b..0a4e44f7f5 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs @@ -711,6 +711,30 @@ public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached item.CanMoveFiles.Should().BeTrue(); } + [TestCase("pausedUP")] + [TestCase("stoppedUP")] + public void should_be_removable_and_should_allow_move_files_if_max_ratio_reached_after_rounding_and_paused(string state) + { + GivenGlobalSeedLimits(1.0f); + GivenCompletedTorrent(state, ratio: 1.1006066990976857f); + + var item = Subject.GetItems().Single(); + item.CanBeRemoved.Should().BeTrue(); + item.CanMoveFiles.Should().BeTrue(); + } + + [TestCase("pausedUP")] + [TestCase("stoppedUP")] + public void should_be_removable_and_should_allow_move_files_if_just_under_max_ratio_reached_after_rounding_and_paused(string state) + { + GivenGlobalSeedLimits(1.0f); + GivenCompletedTorrent(state, ratio: 0.9999f); + + var item = Subject.GetItems().Single(); + item.CanBeRemoved.Should().BeTrue(); + item.CanMoveFiles.Should().BeTrue(); + } + [TestCase("pausedUP")] [TestCase("stoppedUP")] public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_and_paused(string state) @@ -723,6 +747,30 @@ public void should_be_removable_and_should_allow_move_files_if_overridden_max_ra item.CanMoveFiles.Should().BeTrue(); } + [TestCase("pausedUP")] + [TestCase("stoppedUP")] + public void should_be_removable_and_should_allow_move_files_if_overridden_max_ratio_reached_after_rounding_and_paused(string state) + { + GivenGlobalSeedLimits(2.0f); + GivenCompletedTorrent(state, ratio: 1.1006066990976857f, ratioLimit: 1.1f); + + var item = Subject.GetItems().Single(); + item.CanBeRemoved.Should().BeTrue(); + item.CanMoveFiles.Should().BeTrue(); + } + + [TestCase("pausedUP")] + [TestCase("stoppedUP")] + public void should_be_removable_and_should_allow_move_files_if_just_under_overridden_max_ratio_reached_after_rounding_and_paused(string state) + { + GivenGlobalSeedLimits(2.0f); + GivenCompletedTorrent(state, ratio: 0.9999f, ratioLimit: 1.0f); + + var item = Subject.GetItems().Single(); + item.CanBeRemoved.Should().BeTrue(); + item.CanMoveFiles.Should().BeTrue(); + } + [TestCase("pausedUP")] [TestCase("stoppedUP")] public void should_not_be_removable_if_overridden_max_ratio_not_reached_and_paused(string state) diff --git a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs index d533354650..f5c9fe450d 100644 --- a/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/QBittorrent/QBittorrent.cs @@ -630,14 +630,14 @@ protected bool HasReachedSeedLimit(QBittorrentTorrent torrent, QBittorrentPrefer { if (torrent.RatioLimit >= 0) { - if (torrent.Ratio >= torrent.RatioLimit) + if (torrent.RatioLimit - torrent.Ratio <= 0.001f) { return true; } } else if (torrent.RatioLimit == -2 && config.MaxRatioEnabled) { - if (Math.Round(torrent.Ratio, 2) >= config.MaxRatio) + if (config.MaxRatio - torrent.Ratio <= 0.001f) { return true; }