Skip to content

Commit 4c89e24

Browse files
committed
[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.
1 parent 6395c8e commit 4c89e24

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/functional/p2p_dns_seeds.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test ThreadDNSAddressSeed logic for querying DNS seeds."""
66

7+
import itertools
8+
79
from test_framework.p2p import P2PInterface
810
from test_framework.test_framework import BitcoinTestFramework
911

@@ -19,6 +21,7 @@ def run_test(self):
1921
self.existing_outbound_connections_test()
2022
self.existing_block_relay_connections_test()
2123
self.force_dns_test()
24+
self.wait_time_tests()
2225

2326
def init_arg_tests(self):
2427
fakeaddr = "fakenodeaddr.fakedomain.invalid."
@@ -90,6 +93,37 @@ def force_dns_test(self):
9093
# Restore default for subsequent tests
9194
self.restart_node(0)
9295

96+
def wait_time_tests(self):
97+
self.log.info("Check the delay before querying DNS seeds")
98+
99+
# Populate addrman with < 1000 addresses
100+
for i in range(5):
101+
a = f"192.0.0.{i}"
102+
self.nodes[0].addpeeraddress(a, 8333)
103+
104+
# The delay should be 11 seconds
105+
with self.nodes[0].assert_debug_log(expected_msgs=["Waiting 11 seconds before querying DNS seeds.\n"]):
106+
self.restart_node(0)
107+
108+
# Populate addrman with > 1000 addresses
109+
for i in itertools.count():
110+
first_octet = i % 2 + 1
111+
second_octet = i % 256
112+
third_octet = i % 100
113+
a = f"{first_octet}.{second_octet}.{third_octet}.1"
114+
self.nodes[0].addpeeraddress(a, 8333)
115+
if (i > 1000 and i % 100 == 0):
116+
# The addrman size is non-deterministic because new addresses
117+
# are sorted into buckets, potentially displacing existing
118+
# addresses. Periodically check if we have met the desired
119+
# threshold.
120+
if len(self.nodes[0].getnodeaddresses(0)) > 1000:
121+
break
122+
123+
# The delay should be 5 mins
124+
with self.nodes[0].assert_debug_log(expected_msgs=["Waiting 300 seconds before querying DNS seeds.\n"]):
125+
self.restart_node(0)
126+
93127

94128
if __name__ == '__main__':
95129
P2PDNSSeeds().main()

0 commit comments

Comments
 (0)