Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GuiDBTuples credit mining removal #2398

Merged
merged 4 commits into from
Oct 19, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test for native loading
Squashed commits with :
- Use looping call in checking loaded torrent
  • Loading branch information
ardhipoetra committed Oct 19, 2016
commit 5b6a6f0afc07b0c161e4732ed51519cbc3703a36
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