4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Test ThreadDNSAddressSeed logic for querying DNS seeds."""
6
6
7
+ import itertools
8
+
7
9
from test_framework .p2p import P2PInterface
8
10
from test_framework .test_framework import BitcoinTestFramework
9
11
@@ -19,6 +21,7 @@ def run_test(self):
19
21
self .existing_outbound_connections_test ()
20
22
self .existing_block_relay_connections_test ()
21
23
self .force_dns_test ()
24
+ self .wait_time_tests ()
22
25
23
26
def init_arg_tests (self ):
24
27
fakeaddr = "fakenodeaddr.fakedomain.invalid."
@@ -90,6 +93,37 @@ def force_dns_test(self):
90
93
# Restore default for subsequent tests
91
94
self .restart_node (0 )
92
95
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
+
93
127
94
128
if __name__ == '__main__' :
95
129
P2PDNSSeeds ().main ()
0 commit comments