summaryrefslogtreecommitdiffstats
path: root/deluge
diff options
context:
space:
mode:
authorChase Sterling <chase.sterling@gmail.com>2022-02-11 11:44:29 -0500
committerCalum Lind <calumlind+deluge@gmail.com>2022-02-12 17:12:05 +0000
commit374997a8d7fec910a3a63d4171a6a64bab08d3ef (patch)
treed7de943981eead28bc3cbc10cd24350a2f4fd63a /deluge
parentdabb5053761644d06a4decaac7a4edaaa42f4412 (diff)
downloaddeluge-374997a8d7fec910a3a63d4171a6a64bab08d3ef.tar.gz
deluge-374997a8d7fec910a3a63d4171a6a64bab08d3ef.tar.bz2
deluge-374997a8d7fec910a3a63d4171a6a64bab08d3ef.zip
[Tests] Make file priority test more consistent.
Our file priority test was using time.sleep to wait until libtorrent had processed the command. This was sometimes not long enough and the test would fail. On libtorrent 2.0.3+ there is an alert when the process has finished, switch to waiting for that in this test to make the test more consistent. On older libtorrent, make the delay a bit longer, to try to make the test more consistent there as well. Closes: https://github.com/deluge-torrent/deluge/pull/373
Diffstat (limited to 'deluge')
-rw-r--r--deluge/tests/test_torrent.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/deluge/tests/test_torrent.py b/deluge/tests/test_torrent.py
index d84b9b46c..811fc3f5b 100644
--- a/deluge/tests/test_torrent.py
+++ b/deluge/tests/test_torrent.py
@@ -10,6 +10,7 @@ from base64 import b64encode
from unittest import mock
import pytest
+import pytest_twisted
from twisted.internet import defer, reactor
from twisted.internet.task import deferLater
@@ -80,7 +81,19 @@ class TestTorrent(BaseTestCase):
}
return atp
- def test_set_file_priorities(self):
+ @pytest_twisted.ensureDeferred
+ async def test_set_file_priorities(self):
+ if getattr(lt, 'file_prio_alert', None):
+ # Libtorrent 2.0.3 and later has a file_prio_alert
+ prios_set = defer.Deferred()
+ prios_set.addTimeout(1.5, reactor)
+ component.get('AlertManager').register_handler(
+ 'file_prio_alert', lambda a: prios_set.callback(True)
+ )
+ else:
+ # On older libtorrent, we just wait a while
+ prios_set = deferLater(reactor, 0.8)
+
atp = self.get_torrent_atp('dir_with_6_files.torrent')
handle = self.session.add_torrent(atp)
torrent = Torrent(handle, {})
@@ -95,7 +108,7 @@ class TestTorrent(BaseTestCase):
# Test with handle.piece_priorities as handle.file_priorities async
# updates and will return old value. Also need to remove a priority
# value as one file is much smaller than piece size so doesn't show.
- time.sleep(0.6) # Delay to wait for alert from lt
+ await prios_set # Delay to wait for alert from lt
piece_prio = handle.piece_priorities()
result = all(p in piece_prio for p in [3, 2, 0, 5, 6, 7])
assert result