From a8978661093500df8d8dcf2a9c90837afacd0aab Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:57:58 +0530 Subject: [PATCH] [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 --- test/functional/feature_addrman.py | 7 +------ test/functional/test_framework/test_framework.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py index 9839993115a..20adad1e520 100755 --- a/test/functional/feature_addrman.py +++ b/test/functional/feature_addrman.py @@ -157,12 +157,7 @@ class AddrmanTest(BitcoinTestFramework): ) self.log.info("Check that missing addrman is recreated") - self.stop_node(0) - os.remove(peers_dat) - with self.nodes[0].assert_debug_log([ - f'Creating peers.dat because the file was not found ("{peers_dat}")', - ]): - self.start_node(0) + self.restart_node(0, clear_addrman=True) assert_equal(self.nodes[0].getnodeaddresses(), []) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 0ee332b75bf..7f56842b04c 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -577,10 +577,16 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): # Wait for nodes to stop node.wait_until_stopped() - def restart_node(self, i, extra_args=None): + def restart_node(self, i, extra_args=None, clear_addrman=False): """Stop and start a test node""" self.stop_node(i) - self.start_node(i, extra_args) + if clear_addrman: + peers_dat = self.nodes[i].chain_path / "peers.dat" + os.remove(peers_dat) + with self.nodes[i].assert_debug_log(expected_msgs=[f'Creating peers.dat because the file was not found ("{peers_dat}")']): + self.start_node(i, extra_args) + else: + self.start_node(i, extra_args) def wait_for_node_exit(self, i, timeout): self.nodes[i].process.wait(timeout)