Skip to content

Commit

Permalink
Add test for native loading
Browse files Browse the repository at this point in the history
Squashed commits with :
- Use looping call in checking loaded torrent
  • Loading branch information
ardhipoetra committed Oct 19, 2016
1 parent 7c7c99b commit 5b6a6f0
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Tribler/Test/Core/CreditMining/test_creditmining_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -387,6 +388,8 @@ def check_torrents_channel(src, defer_param=None, target=1):
if src_obj.community:
src_obj.community.cancel_all_pending_tasks()

self.assertEqual(src_obj.get_source_text(), 'Simple Channel')

defer_param.callback(src)

return defer_param
Expand Down Expand Up @@ -517,6 +520,58 @@ def check_torrents_channel(src, defer_param=None):
d.addCallback(check_torrents_channel)
return d

@deferred(timeout=40)
def test_chn_native_load(self):
self.session.get_dispersy = lambda: True
self.session.lm.dispersy = Dispersy(ManualEnpoint(0), self.getStateDir())
dispersy_cid_hex = "abcd" * 9 + "0012"
dispersy_cid = binascii.unhexlify(dispersy_cid_hex)

# create channel and insert torrent
self.create_fake_allchannel_community()
self.create_torrents_in_channel(dispersy_cid_hex)

self.session.download_torrentfile = \
lambda dummy_ihash, function, _: function(binascii.hexlify(TORRENT_FILE_INFOHASH))

def get_bin_torrent(_):
"""
get binary data of a torrent
"""
f = open(TORRENT_FILE, "rb")
bdata = f.read()
f.close()
return bdata

self.session.get_collected_torrent = get_bin_torrent

self.boosting_manager.add_source(dispersy_cid)

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)

return defer_param

defer_ret = self.check_source(dispersy_cid)
defer_ret.addCallback(_loop_check)

return defer_ret

def tearDown(self):
self.session.lm.dispersy._communities['allchannel'].cancel_all_pending_tasks()
self.session.lm.dispersy.cancel_all_pending_tasks()
Expand Down

0 comments on commit 5b6a6f0

Please sign in to comment.