diff options
author | Chase Sterling <chase.sterling@gmail.com> | 2022-02-08 14:34:02 -0500 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2022-02-15 15:14:40 +0000 |
commit | 8ff4683780921111f26fe051e0274aac8afe8bf3 (patch) | |
tree | cb1c6a142ceae8860001c676a8d570ab451ddb8b /deluge/tests/test_torrent.py | |
parent | 62a40521789eab273415550ea741ed668b2e947e (diff) | |
download | deluge-8ff4683780921111f26fe051e0274aac8afe8bf3.tar.gz deluge-8ff4683780921111f26fe051e0274aac8afe8bf3.tar.bz2 deluge-8ff4683780921111f26fe051e0274aac8afe8bf3.zip |
Automatically refresh and expire the torrent status cache.
Stop at ratio was not working when no clients were connected, because
it was using a cached version of the torrent status, and never calling
for a refresh. When a client connected, it called for the refresh and
started working properly.
Closes: https://dev.deluge-torrent.org/ticket/3497
Closes: https://github.com/deluge-torrent/deluge/pull/369
Diffstat (limited to 'deluge/tests/test_torrent.py')
-rw-r--r-- | deluge/tests/test_torrent.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/deluge/tests/test_torrent.py b/deluge/tests/test_torrent.py index 6c07531dd..36adc0fde 100644 --- a/deluge/tests/test_torrent.py +++ b/deluge/tests/test_torrent.py @@ -3,7 +3,7 @@ # the additional special exception to link portions of this program with the OpenSSL library. # See LICENSE for more details. # - +import itertools import os import time from base64 import b64encode @@ -356,3 +356,20 @@ class TestTorrent(BaseTestCase): self.torrent = Torrent(handle, {}) assert not self.torrent.connect_peer('127.0.0.1', 'text') assert self.torrent.connect_peer('127.0.0.1', '1234') + + def test_status_cache(self): + atp = self.get_torrent_atp('test_torrent.file.torrent') + handle = self.session.add_torrent(atp) + mock_time = mock.Mock(return_value=time.time()) + with mock.patch('time.time', mock_time): + torrent = Torrent(handle, {}) + counter = itertools.count() + handle.status = mock.Mock(side_effect=counter.__next__) + first_status = torrent.get_lt_status() + assert first_status == 0, 'sanity check' + assert first_status == torrent.status, 'cached status should be used' + assert torrent.get_lt_status() == 1, 'status should update' + assert torrent.status == 1 + # Advance time and verify cache expires and updates + mock_time.return_value += 10 + assert torrent.status == 2 |