Skip to content

Commit

Permalink
Add test for native loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ardhipoetra committed Oct 18, 2016
1 parent 93be4f9 commit db62c75
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Tribler/Test/Core/CreditMining/test_creditmining_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,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 +519,52 @@ def check_torrents_channel(src, defer_param=None):
d.addCallback(check_torrents_channel)
return d

@deferred(timeout=20)
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 check_loaded(src, defer_param=None):
"""
check if a torrent has been loaded
"""
if defer_param is None:
defer_param = defer.Deferred()

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)

return d

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 db62c75

Please sign in to comment.