From 545930cea4dae62db7c1107a52323f42dabfae56 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 29 May 2018 16:16:19 -0400 Subject: [PATCH] dht test environment fixes --- lbrynet/tests/functional/dht/dht_test_environment.py | 11 ++++++----- lbrynet/tests/functional/dht/mock_transport.py | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lbrynet/tests/functional/dht/dht_test_environment.py b/lbrynet/tests/functional/dht/dht_test_environment.py index 57af2c68a..debf061e0 100644 --- a/lbrynet/tests/functional/dht/dht_test_environment.py +++ b/lbrynet/tests/functional/dht/dht_test_environment.py @@ -1,6 +1,7 @@ import logging from twisted.trial import unittest from twisted.internet import defer, task +from lbrynet.dht import constants from lbrynet.dht.node import Node from mock_transport import resolve, listenUDP, MOCK_DHT_SEED_DNS, mock_node_generator @@ -45,8 +46,8 @@ class TestKademliaBase(unittest.TestCase): """ for _ in range(int(n * (1.0 / float(step)))): self.clock.advance(step) - if tick_callback and callable(tick_callback): - tick_callback(self.clock.seconds()) + if tick_callback and callable(tick_callback): + tick_callback(self.clock.seconds()) def run_reactor(self, seconds, deferreds, tick_callback=None): d = defer.DeferredList(deferreds) @@ -110,14 +111,14 @@ class TestKademliaBase(unittest.TestCase): seed_dl.append( seed.start(known_addresses) ) - yield self.run_reactor(901, seed_dl) + yield self.run_reactor(constants.checkRefreshInterval+1, seed_dl) while len(self.nodes + self._seeds) < self.network_size: network_dl = [] for i in range(min(10, self.network_size - len(self._seeds) - len(self.nodes))): network_dl.append(self.add_node()) - yield self.run_reactor(31, network_dl) + yield self.run_reactor(constants.checkRefreshInterval*2+1, network_dl) self.assertEqual(len(self.nodes + self._seeds), self.network_size) - self.pump_clock(1800) + self.pump_clock(3600) self.verify_all_nodes_are_routable() self.verify_all_nodes_are_pingable() diff --git a/lbrynet/tests/functional/dht/mock_transport.py b/lbrynet/tests/functional/dht/mock_transport.py index 3ce0bae76..c46ad30e2 100644 --- a/lbrynet/tests/functional/dht/mock_transport.py +++ b/lbrynet/tests/functional/dht/mock_transport.py @@ -1,7 +1,7 @@ import struct +import hashlib import logging from twisted.internet import defer, error -from lbrynet.core.utils import generate_id from lbrynet.dht.encoding import Bencode from lbrynet.dht.error import DecodeError from lbrynet.dht.msgformat import DefaultFormat @@ -121,7 +121,9 @@ def mock_node_generator(count=None, mock_node_ids=MOCK_DHT_NODES): if count and num >= count: break if num >= len(mock_node_ids): - node_id = generate_id().encode('hex') + h = hashlib.sha384() + h.update("node %i" % num) + node_id = h.hexdigest() else: node_id = mock_node_ids[num] yield (node_id, node_ip)