Skip to content

Commit bf3189e

Browse files
author
MarcoFalke
committed
Merge #21165: test: Use mocktime in test_seed_peers
d4187e4 [test] Use mocktime in test_seed_peers() (Dhruv Mehta) 015637d [refactor] Correct log message in net.cpp (Dhruv Mehta) Pull request description: The test now takes less than 5 seconds instead of more than 2 minutes Further context: https://github.com/bitcoin/bitcoin/pull/19884/files#r575336503 Before: ``` 2021-02-12T17:22:25.980000Z TestFramework (INFO): Test seed peers, this will take about 2 minutes 2021-02-12T17:24:30.472000Z TestFramework (INFO): Test -networkactive option ``` After: ``` 2021-02-12T17:33:39.224000Z TestFramework (INFO): Test seed peers 2021-02-12T17:33:43.139000Z TestFramework (INFO): Test -networkactive option ``` Top commit has no ACKs. Tree-SHA512: 6d8df7d4433c96268694577e4c10a346785e076d45fa220091875e55def200100e7b827fac2a1f7853a2c2c39e9661e06288dca8c645da9e13d4318a4ff2172e
2 parents e9c037b + d4187e4 commit bf3189e

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
18131813
LOCK2(m_addr_fetches_mutex, cs_vAddedNodes);
18141814
if (m_addr_fetches.empty() && vAddedNodes.empty()) {
18151815
add_fixed_seeds_now = true;
1816-
LogPrintf("Adding fixed seeds as -dnsseed=0, -addnode is not provided and and all -seednode(s) attempted\n");
1816+
LogPrintf("Adding fixed seeds as -dnsseed=0, -addnode is not provided and all -seednode(s) attempted\n");
18171817
}
18181818
}
18191819

test/functional/feature_config_args.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,21 @@ def test_networkactive(self):
149149
self.stop_node(0)
150150

151151
def test_seed_peers(self):
152-
self.log.info('Test seed peers, this will take about 2 minutes')
152+
self.log.info('Test seed peers')
153153
default_data_dir = self.nodes[0].datadir
154154

155155
# No peers.dat exists and -dnsseed=1
156156
# We expect the node will use DNS Seeds, but Regtest mode has 0 DNS seeds
157157
# So after 60 seconds, the node should fallback to fixed seeds (this is a slow test)
158158
assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
159-
start = time.time()
159+
start = int(time.time())
160160
with self.nodes[0].assert_debug_log(expected_msgs=[
161161
"Loaded 0 addresses from peers.dat",
162-
"0 addresses found from DNS seeds",
163-
"Adding fixed seeds as 60 seconds have passed and addrman is empty"], timeout=80):
164-
self.start_node(0, extra_args=['-dnsseed=1'])
165-
assert time.time() - start >= 60
162+
"0 addresses found from DNS seeds"]):
163+
self.start_node(0, extra_args=['-dnsseed=1 -mocktime={}'.format(start)])
164+
with self.nodes[0].assert_debug_log(expected_msgs=[
165+
"Adding fixed seeds as 60 seconds have passed and addrman is empty"]):
166+
self.nodes[0].setmocktime(start + 65)
166167
self.stop_node(0)
167168

168169
# No peers.dat exists and -dnsseed=0
@@ -172,7 +173,7 @@ def test_seed_peers(self):
172173
with self.nodes[0].assert_debug_log(expected_msgs=[
173174
"Loaded 0 addresses from peers.dat",
174175
"DNS seeding disabled",
175-
"Adding fixed seeds as -dnsseed=0, -addnode is not provided and and all -seednode(s) attempted\n"]):
176+
"Adding fixed seeds as -dnsseed=0, -addnode is not provided and all -seednode(s) attempted\n"]):
176177
self.start_node(0, extra_args=['-dnsseed=0'])
177178
assert time.time() - start < 60
178179
self.stop_node(0)
@@ -192,14 +193,14 @@ def test_seed_peers(self):
192193
# No peers.dat exists and -dnsseed=0, but a -addnode is provided
193194
# We expect the node will allow 60 seconds prior to using fixed seeds
194195
assert not os.path.exists(os.path.join(default_data_dir, "peers.dat"))
195-
start = time.time()
196+
start = int(time.time())
196197
with self.nodes[0].assert_debug_log(expected_msgs=[
197198
"Loaded 0 addresses from peers.dat",
198-
"DNS seeding disabled",
199-
"Adding fixed seeds as 60 seconds have passed and addrman is empty"],
200-
timeout=80):
201-
self.start_node(0, extra_args=['-dnsseed=0', '-addnode=fakenodeaddr'])
202-
assert time.time() - start >= 60
199+
"DNS seeding disabled"]):
200+
self.start_node(0, extra_args=['-dnsseed=0', '-addnode=fakenodeaddr -mocktime={}'.format(start)])
201+
with self.nodes[0].assert_debug_log(expected_msgs=[
202+
"Adding fixed seeds as 60 seconds have passed and addrman is empty"]):
203+
self.nodes[0].setmocktime(start + 65)
203204
self.stop_node(0)
204205

205206

0 commit comments

Comments
 (0)