diff --git a/lbrynet/core/server/DHTHashAnnouncer.py b/lbrynet/core/server/DHTHashAnnouncer.py index a68a97d0f..69e5123aa 100644 --- a/lbrynet/core/server/DHTHashAnnouncer.py +++ b/lbrynet/core/server/DHTHashAnnouncer.py @@ -3,14 +3,13 @@ import collections import logging import time -from twisted.internet import defer, reactor - +from twisted.internet import defer +from lbrynet.core import utils log = logging.getLogger(__name__) class DHTHashAnnouncer(object): - callLater = reactor.callLater ANNOUNCE_CHECK_INTERVAL = 60 CONCURRENT_ANNOUNCERS = 5 @@ -26,7 +25,7 @@ class DHTHashAnnouncer(object): def run_manage_loop(self): if self.peer_port is not None: self._announce_available_hashes() - self.next_manage_call = self.callLater(self.ANNOUNCE_CHECK_INTERVAL, self.run_manage_loop) + self.next_manage_call = utils.call_later(self.ANNOUNCE_CHECK_INTERVAL, self.run_manage_loop) def stop(self): log.info("Stopping %s", self) @@ -79,7 +78,7 @@ class DHTHashAnnouncer(object): log.debug('Announcing blob %s to dht', h) d = self.dht_node.announceHaveBlob(binascii.unhexlify(h), self.peer_port) d.chainDeferred(announce_deferred) - d.addBoth(lambda _: self.callLater(0, announce)) + d.addBoth(lambda _: utils.call_later(0, announce)) else: self._concurrent_announcers -= 1 diff --git a/tests/unit/core/server/test_DHTHashAnnouncer.py b/tests/unit/core/server/test_DHTHashAnnouncer.py index c6bb05967..fdeea9664 100644 --- a/tests/unit/core/server/test_DHTHashAnnouncer.py +++ b/tests/unit/core/server/test_DHTHashAnnouncer.py @@ -2,9 +2,7 @@ import os import binascii from twisted.trial import unittest from twisted.internet import defer,task -from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer,DHTHashSupplier -from lbrynet.core.utils import random_string -from lbrynet.core import log_support +from lbrynet.core import log_support, utils class MocDHTNode(object): @@ -35,8 +33,9 @@ class DHTHashAnnouncerTest(unittest.TestCase): self.blobs_to_announce.append(binascii.b2a_hex(os.urandom(32))) self.clock = task.Clock() self.dht_node = MocDHTNode() + utils.call_later = self.clock.callLater + from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer,DHTHashSupplier self.announcer = DHTHashAnnouncer(self.dht_node, peer_port=3333) - self.announcer.callLater = self.clock.callLater self.supplier = MocSupplier(self.blobs_to_announce) self.announcer.add_supplier(self.supplier)