diff --git a/Tribler/Test/Core/CreditMining/test_creditmining_sys.py b/Tribler/Test/Core/CreditMining/test_creditmining_sys.py index a0e9db21259..1dce79614c6 100644 --- a/Tribler/Test/Core/CreditMining/test_creditmining_sys.py +++ b/Tribler/Test/Core/CreditMining/test_creditmining_sys.py @@ -7,6 +7,7 @@ import binascii import os import shutil +from twisted.internet.task import LoopingCall from twisted.internet import defer from twisted.web.server import Site @@ -519,7 +520,7 @@ def check_torrents_channel(src, defer_param=None): d.addCallback(check_torrents_channel) return d - @deferred(timeout=20) + @deferred(timeout=40) def test_chn_native_load(self): self.session.get_dispersy = lambda: True self.session.lm.dispersy = Dispersy(ManualEnpoint(0), self.getStateDir()) @@ -546,24 +547,30 @@ def get_bin_torrent(_): self.boosting_manager.add_source(dispersy_cid) - def check_loaded(src, defer_param=None): - """ - check if a torrent has been loaded - """ - if defer_param is None: - defer_param = defer.Deferred() + def _loop_check(_): + defer_param = defer.Deferred() + + def check_loaded(src): + """ + check if a torrent has been loaded + """ + src_obj = self.boosting_manager.get_source_object(src) + if src_obj.loaded_torrent[TORRENT_FILE_INFOHASH] is not None: + src_obj.community.cancel_all_pending_tasks() + src_obj.kill_tasks() + self.check_loaded_lc.stop() + self.check_loaded_lc = None + defer_param.callback(src) + + self.check_loaded_lc = LoopingCall(check_loaded, dispersy_cid) + self.check_loaded_lc.start(1, now=True) - src_obj = self.boosting_manager.get_source_object(src) - if src_obj.loaded_torrent[TORRENT_FILE_INFOHASH] is not None: - src_obj.community.cancel_all_pending_tasks() - src_obj.kill_tasks() - defer_param.callback(src) return defer_param - d = self.check_source(dispersy_cid) - d.addCallback(check_loaded) + defer_ret = self.check_source(dispersy_cid) + defer_ret.addCallback(_loop_check) - return d + return defer_ret def tearDown(self): self.session.lm.dispersy._communities['allchannel'].cancel_all_pending_tasks()