result must be set here, otherwise it will not be defined when used later. Add test for it
This commit is contained in:
parent
0425c95b68
commit
4cb461601e
2 changed files with 18 additions and 3 deletions
|
@ -118,6 +118,7 @@ class DHTHashAnnouncer(object):
|
|||
log.debug("No nodes stored %s, retrying", blob_hash)
|
||||
result = yield do_store(blob_hash, announce_d)
|
||||
else:
|
||||
result = {}
|
||||
log.warning("No nodes stored %s", blob_hash)
|
||||
else:
|
||||
result = store_nodes
|
||||
|
|
|
@ -4,17 +4,24 @@ from twisted.internet import defer, reactor
|
|||
from lbrynet.tests.util import random_lbry_hash
|
||||
from lbrynet.core.server.DHTHashAnnouncer import DHTHashAnnouncer
|
||||
|
||||
|
||||
class MocDHTNode(object):
|
||||
def __init__(self):
|
||||
def __init__(self, announce_will_fail=False):
|
||||
# if announce_will_fail is True,
|
||||
# announceHaveBlob will return empty dict
|
||||
self.can_store = True
|
||||
self.blobs_announced = 0
|
||||
self.announce_will_fail = announce_will_fail
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def announceHaveBlob(self, blob):
|
||||
if self.announce_will_fail:
|
||||
return_val = {}
|
||||
else:
|
||||
return_val = {blob:["ab"*48]}
|
||||
|
||||
self.blobs_announced += 1
|
||||
d = defer.Deferred(None)
|
||||
reactor.callLater(1, d.callback, {blob: ["ab" * 48]})
|
||||
reactor.callLater(1, d.callback, return_val)
|
||||
result = yield d
|
||||
defer.returnValue(result)
|
||||
|
||||
|
@ -45,6 +52,13 @@ class DHTHashAnnouncerTest(unittest.TestCase):
|
|||
self.supplier = MocSupplier(self.blobs_to_announce)
|
||||
self.announcer.add_supplier(self.supplier)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_announce_fail(self):
|
||||
# test what happens when node.announceHaveBlob() returns empty dict
|
||||
self.dht_node.announce_will_fail = True
|
||||
d = yield self.announcer._announce_available_hashes()
|
||||
yield d
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_basic(self):
|
||||
d = self.announcer._announce_available_hashes()
|
||||
|
|
Loading…
Reference in a new issue