test re-join dht

This commit is contained in:
Jack Robison 2018-05-24 12:57:20 -04:00
parent c521120b17
commit 98e21cdba0
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 70 additions and 24 deletions

View file

@ -39,27 +39,3 @@ class TestPeerExpiration(TestKademliaBase):
self.assertTrue(len(get_nodes_with_stale_contacts()) == 0) self.assertTrue(len(get_nodes_with_stale_contacts()) == 0)
self.verify_all_nodes_are_routable() self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable() self.verify_all_nodes_are_pingable()
class TestReJoinExpiredPeer(TestKademliaBase):
network_size = 40
@defer.inlineCallbacks
def test_re_join_expired_peer(self):
removed_node = self.nodes[0]
self.nodes.remove(removed_node)
yield self.run_reactor(1, [removed_node.stop()])
# run the network for an hour, which should expire the removed node
for _ in range(60):
self.pump_clock(60)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()
self.nodes.append(removed_node)
yield self.run_reactor(
31, [removed_node.start([(seed_name, 4444) for seed_name in sorted(self.seed_dns.keys())])]
)
self.pump_clock(901)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()

View file

@ -0,0 +1,70 @@
import logging
from twisted.internet import defer
from dht_test_environment import TestKademliaBase
log = logging.getLogger()
class TestReJoin(TestKademliaBase):
network_size = 40
@defer.inlineCallbacks
def test_re_join(self):
removed_node = self.nodes[0]
self.nodes.remove(removed_node)
yield self.run_reactor(1, [removed_node.stop()])
# run the network for an hour, which should expire the removed node
self.pump_clock(3600)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()
self.nodes.append(removed_node)
yield self.run_reactor(
31, [removed_node.start([(seed_name, 4444) for seed_name in sorted(self.seed_dns.keys())])]
)
self.pump_clock(901)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()
@defer.inlineCallbacks
def test_re_join_with_new_ip(self):
removed_node = self.nodes[0]
self.nodes.remove(removed_node)
yield self.run_reactor(1, [removed_node.stop()])
# run the network for an hour, which should expire the removed node
for _ in range(60):
self.pump_clock(60)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()
removed_node.externalIP = "10.43.43.43"
self.nodes.append(removed_node)
yield self.run_reactor(
31, [removed_node.start([(seed_name, 4444) for seed_name in sorted(self.seed_dns.keys())])]
)
self.pump_clock(901)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()
@defer.inlineCallbacks
def test_re_join_with_new_node_id(self):
removed_node = self.nodes[0]
self.nodes.remove(removed_node)
yield self.run_reactor(1, [removed_node.stop()])
# run the network for an hour, which should expire the removed node
for _ in range(60):
self.pump_clock(60)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()
removed_node.node_id = removed_node._generateID()
self.nodes.append(removed_node)
yield self.run_reactor(
31, [removed_node.start([(seed_name, 4444) for seed_name in sorted(self.seed_dns.keys())])]
)
self.pump_clock(901)
self.verify_all_nodes_are_routable()
self.verify_all_nodes_are_pingable()