From c27fe7af31ec95c46965b38036fe7aee9eb0effc Mon Sep 17 00:00:00 2001 From: Kay Kurokawa Date: Thu, 16 Feb 2017 16:25:57 -0500 Subject: [PATCH] use utils.call_later in ConnectionManager --- lbrynet/core/client/ConnectionManager.py | 7 +++---- tests/unit/core/client/test_ConnectionManager.py | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lbrynet/core/client/ConnectionManager.py b/lbrynet/core/client/ConnectionManager.py index bb06a645b..2bbce9164 100644 --- a/lbrynet/core/client/ConnectionManager.py +++ b/lbrynet/core/client/ConnectionManager.py @@ -5,7 +5,7 @@ from lbrynet import interfaces from lbrynet import conf from lbrynet.core.client.ClientProtocol import ClientProtocolFactory from lbrynet.core.Error import InsufficientFundsError - +from lbrynet.core import utils log = logging.getLogger(__name__) @@ -19,7 +19,6 @@ class PeerConnectionHandler(object): class ConnectionManager(object): implements(interfaces.IConnectionManager) - callLater = reactor.callLater MANAGE_CALL_INTERVAL_SEC = 1 def __init__(self, downloader, rate_limiter, @@ -54,7 +53,7 @@ class ConnectionManager(object): def start(self): log.debug("%s starting", self._get_log_name()) self._start() - self._next_manage_call = self.callLater(0, self.manage) + self._next_manage_call = utils.call_later(0, self.manage) return defer.succeed(True) @@ -156,7 +155,7 @@ class ConnectionManager(object): self._manage_deferred.callback(None) self._manage_deferred = None if not self.stopped and schedule_next_call: - self._next_manage_call = self.callLater(self.MANAGE_CALL_INTERVAL_SEC, self.manage) + self._next_manage_call = utils.call_later(self.MANAGE_CALL_INTERVAL_SEC, self.manage) def _rank_request_creator_connections(self): """Returns an ordered list of our request creators, ranked according diff --git a/tests/unit/core/client/test_ConnectionManager.py b/tests/unit/core/client/test_ConnectionManager.py index 0aee113d3..81d69429e 100644 --- a/tests/unit/core/client/test_ConnectionManager.py +++ b/tests/unit/core/client/test_ConnectionManager.py @@ -3,7 +3,7 @@ import time import logging from lbrynet.core import log_support -from lbrynet.core.client.ConnectionManager import ConnectionManager +#from lbrynet.core.client.ConnectionManager import ConnectionManager from lbrynet.core.client.ClientRequest import ClientRequest from lbrynet.core.server.ServerProtocol import ServerProtocol from lbrynet.core.RateLimiter import RateLimiter @@ -16,6 +16,7 @@ from twisted.internet import defer, reactor, task from twisted.internet.task import deferLater from twisted.internet.protocol import Protocol, ServerFactory from lbrynet import conf +from lbrynet.core import utils from lbrynet.interfaces import IQueryHandlerFactory, IQueryHandler, IRequestCreator from zope.interface import implements @@ -122,11 +123,12 @@ class TestIntegrationConnectionManager(unittest.TestCase): self.downloader = MocDownloader() self.rate_limiter = RateLimiter() self.primary_request_creator = MocRequestCreator([self.TEST_PEER]) + self.clock = task.Clock() + utils.call_later = self.clock.callLater + from lbrynet.core.client.ConnectionManager import ConnectionManager self.connection_manager = ConnectionManager(self.downloader, self.rate_limiter, [self.primary_request_creator], []) - self.clock = task.Clock() - self.connection_manager.callLater = self.clock.callLater self.connection_manager._start() self.server_port = None