Skip to content

Commit a897866

Browse files
committed
[test] Restart a node with empty addrman
Currently in tests where we are interested in contents of addrman, addresses which were added to the node's addrman in previous tests leak into the current test. example: addresses added in addpeeraddress test leak into getaddrmaninfo and getrawaddrman tests. It is cleaner to design the tests to be modular and without such leaks so that we don't need to deal with context from previous tests
1 parent 71c1991 commit a897866

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

test/functional/feature_addrman.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,7 @@ def run_test(self):
157157
)
158158

159159
self.log.info("Check that missing addrman is recreated")
160-
self.stop_node(0)
161-
os.remove(peers_dat)
162-
with self.nodes[0].assert_debug_log([
163-
f'Creating peers.dat because the file was not found ("{peers_dat}")',
164-
]):
165-
self.start_node(0)
160+
self.restart_node(0, clear_addrman=True)
166161
assert_equal(self.nodes[0].getnodeaddresses(), [])
167162

168163

test/functional/test_framework/test_framework.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,16 @@ def stop_nodes(self, wait=0):
577577
# Wait for nodes to stop
578578
node.wait_until_stopped()
579579

580-
def restart_node(self, i, extra_args=None):
580+
def restart_node(self, i, extra_args=None, clear_addrman=False):
581581
"""Stop and start a test node"""
582582
self.stop_node(i)
583-
self.start_node(i, extra_args)
583+
if clear_addrman:
584+
peers_dat = self.nodes[i].chain_path / "peers.dat"
585+
os.remove(peers_dat)
586+
with self.nodes[i].assert_debug_log(expected_msgs=[f'Creating peers.dat because the file was not found ("{peers_dat}")']):
587+
self.start_node(i, extra_args)
588+
else:
589+
self.start_node(i, extra_args)
584590

585591
def wait_for_node_exit(self, i, timeout):
586592
self.nodes[i].process.wait(timeout)

0 commit comments

Comments
 (0)