aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2021-05-24 17:56:22 -0700
committerAmiti Uttarwar <amiti@uttarwar.org>2021-07-30 11:15:49 -0700
commit4c89e24f64c1dc1a56a3bcb6b5e2b4fb95e8b29f (patch)
treee2ed5e9030ce07f9c32b7fb4ff3b046cb8d0678c /test
parent6395c8ed5689ea72e9a1618f14551775246f6361 (diff)
[test] Test the delay before querying DNS seeds
When starting up with a populated addrman, ThreadDNSAddressSeed adds a delay during which time the node may be able to connect to some peers. This commit tests the delay changes based on the number of addresses in the addrman.
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/p2p_dns_seeds.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/functional/p2p_dns_seeds.py b/test/functional/p2p_dns_seeds.py
index d9977dccee..e58ad8e0fc 100755
--- a/test/functional/p2p_dns_seeds.py
+++ b/test/functional/p2p_dns_seeds.py
@@ -4,6 +4,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test ThreadDNSAddressSeed logic for querying DNS seeds."""
+import itertools
+
from test_framework.p2p import P2PInterface
from test_framework.test_framework import BitcoinTestFramework
@@ -19,6 +21,7 @@ class P2PDNSSeeds(BitcoinTestFramework):
self.existing_outbound_connections_test()
self.existing_block_relay_connections_test()
self.force_dns_test()
+ self.wait_time_tests()
def init_arg_tests(self):
fakeaddr = "fakenodeaddr.fakedomain.invalid."
@@ -90,6 +93,37 @@ class P2PDNSSeeds(BitcoinTestFramework):
# Restore default for subsequent tests
self.restart_node(0)
+ def wait_time_tests(self):
+ self.log.info("Check the delay before querying DNS seeds")
+
+ # Populate addrman with < 1000 addresses
+ for i in range(5):
+ a = f"192.0.0.{i}"
+ self.nodes[0].addpeeraddress(a, 8333)
+
+ # The delay should be 11 seconds
+ with self.nodes[0].assert_debug_log(expected_msgs=["Waiting 11 seconds before querying DNS seeds.\n"]):
+ self.restart_node(0)
+
+ # Populate addrman with > 1000 addresses
+ for i in itertools.count():
+ first_octet = i % 2 + 1
+ second_octet = i % 256
+ third_octet = i % 100
+ a = f"{first_octet}.{second_octet}.{third_octet}.1"
+ self.nodes[0].addpeeraddress(a, 8333)
+ if (i > 1000 and i % 100 == 0):
+ # The addrman size is non-deterministic because new addresses
+ # are sorted into buckets, potentially displacing existing
+ # addresses. Periodically check if we have met the desired
+ # threshold.
+ if len(self.nodes[0].getnodeaddresses(0)) > 1000:
+ break
+
+ # The delay should be 5 mins
+ with self.nodes[0].assert_debug_log(expected_msgs=["Waiting 300 seconds before querying DNS seeds.\n"]):
+ self.restart_node(0)
+
if __name__ == '__main__':
P2PDNSSeeds().main()