Skip to content

Commit 4197035

Browse files
hodlinatorluke-jr
authored andcommitted
test refactor: feature_config_args.py - Stop nodes at the end of tests, not at the beginning
This ensures we don't needlessly start the node, and reduces implicit dependencies between test functions. test_seed_peers() - Move assert calling RPC to verify correct chain after our own function actually started the node. Github-Pull: bitcoin#31212 Rebased-From: 312ec64
1 parent 56c374d commit 4197035

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

test/functional/feature_config_args.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,20 @@ def set_test_params(self):
2727
self.wallet_names = []
2828
self.disable_autoconnect = False
2929

30+
# Overridden to avoid attempt to sync not yet started nodes.
31+
def setup_network(self):
32+
self.setup_nodes()
33+
34+
# Overriden to not start nodes automatically - doing so is the
35+
# responsibility of each test function.
36+
def setup_nodes(self):
37+
self.add_nodes(self.num_nodes, self.extra_args)
38+
# Ensure a log file exists as TestNode.assert_debug_log() expects it.
39+
self.nodes[0].debug_log_path.parent.mkdir()
40+
self.nodes[0].debug_log_path.touch()
41+
3042
def test_config_file_parser(self):
3143
self.log.info('Test config file parser')
32-
self.stop_node(0)
3344

3445
# Check that startup fails if conf= is set in bitcoin.conf or in an included conf file
3546
bad_conf_file_path = self.nodes[0].datadir_path / "bitcoin_bad.conf"
@@ -155,12 +166,11 @@ def test_invalid_command_line_options(self):
155166
)
156167

157168
def test_log_buffer(self):
158-
self.stop_node(0)
159169
with self.nodes[0].assert_debug_log(expected_msgs=['Warning: parsed potentially confusing double-negative -connect=0\n']):
160170
self.start_node(0, extra_args=['-noconnect=0'])
171+
self.stop_node(0)
161172

162173
def test_args_log(self):
163-
self.stop_node(0)
164174
self.log.info('Test config args logging')
165175
with self.nodes[0].assert_debug_log(
166176
expected_msgs=[
@@ -189,10 +199,10 @@ def test_args_log(self):
189199
'-rpcuser=secret-rpcuser',
190200
'-torpassword=secret-torpassword',
191201
])
202+
self.stop_node(0)
192203

193204
def test_networkactive(self):
194205
self.log.info('Test -networkactive option')
195-
self.stop_node(0)
196206
with self.nodes[0].assert_debug_log(expected_msgs=['SetNetworkActive: true\n']):
197207
self.start_node(0)
198208

@@ -215,16 +225,12 @@ def test_networkactive(self):
215225
self.stop_node(0)
216226
with self.nodes[0].assert_debug_log(expected_msgs=['SetNetworkActive: false\n']):
217227
self.start_node(0, extra_args=['-nonetworkactive=1'])
228+
self.stop_node(0)
218229

219230
def test_seed_peers(self):
220231
self.log.info('Test seed peers')
221232
default_data_dir = self.nodes[0].datadir_path
222233
peer_dat = default_data_dir / 'peers.dat'
223-
# Only regtest has no fixed seeds. To avoid connections to random
224-
# nodes, regtest is the only network where it is safe to enable
225-
# -fixedseeds in tests
226-
util.assert_equal(self.nodes[0].getblockchaininfo()['chain'],'regtest')
227-
self.stop_node(0)
228234

229235
# No peers.dat exists and -dnsseed=1
230236
# We expect the node will use DNS Seeds, but Regtest mode does not have
@@ -241,6 +247,12 @@ def test_seed_peers(self):
241247
timeout=10,
242248
):
243249
self.start_node(0, extra_args=['-dnsseed=1', '-fixedseeds=1', f'-mocktime={start}'])
250+
251+
# Only regtest has no fixed seeds. To avoid connections to random
252+
# nodes, regtest is the only network where it is safe to enable
253+
# -fixedseeds in tests
254+
util.assert_equal(self.nodes[0].getblockchaininfo()['chain'],'regtest')
255+
244256
with self.nodes[0].assert_debug_log(expected_msgs=[
245257
"Adding fixed seeds as 60 seconds have passed and addrman is empty",
246258
]):
@@ -287,13 +299,13 @@ def test_seed_peers(self):
287299
"Adding fixed seeds as 60 seconds have passed and addrman is empty",
288300
]):
289301
self.nodes[0].setmocktime(start + 65)
302+
self.stop_node(0)
290303

291304
def test_connect_with_seednode(self):
292305
self.log.info('Test -connect with -seednode')
293306
seednode_ignored = ['-seednode is ignored when -connect is used\n']
294307
dnsseed_ignored = ['-dnsseed is ignored when -connect is used and -proxy is specified\n']
295308
addcon_thread_started = ['addcon thread start\n']
296-
self.stop_node(0)
297309

298310
# When -connect is supplied, expanding addrman via getaddr calls to ADDR_FETCH(-seednode)
299311
# nodes is irrelevant and -seednode is ignored.
@@ -318,6 +330,7 @@ def test_connect_with_seednode(self):
318330
with self.nodes[0].assert_debug_log(expected_msgs=addcon_thread_started,
319331
unexpected_msgs=seednode_ignored):
320332
self.restart_node(0, extra_args=[connect_arg, '-seednode=fakeaddress2'])
333+
self.stop_node(0)
321334

322335
def test_ignored_conf(self):
323336
self.log.info('Test error is triggered when the datadir in use contains a bitcoin.conf file that would be ignored '

0 commit comments

Comments
 (0)