From 36b0713edc4655f6e0c291975d6d280fbc89cf2e Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 14 Mar 2025 10:30:50 -0400 Subject: [PATCH] test: fix intermittent failure in wallet_reorgsrestore.py Wait until the node's process has fully stopped before starting a new instance. Since the same code is used in tool_wallet.py, this consolidates the behavior into a 'kill_process()' function. --- test/functional/test_framework/test_node.py | 5 +++++ test/functional/tool_wallet.py | 5 +---- test/functional/wallet_reorgsrestore.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index f7d6ba78d23..52efadb6e22 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -443,6 +443,11 @@ class TestNode(): kwargs["expected_ret_code"] = 1 if expect_error else 0 # Whether node shutdown return EXIT_FAILURE or EXIT_SUCCESS self.wait_until(lambda: self.is_node_stopped(**kwargs), timeout=timeout) + def kill_process(self): + self.process.kill() + self.wait_until_stopped(expected_ret_code=1 if platform.system() == "Windows" else -9) + assert self.is_node_stopped() + def replace_in_config(self, replacements): """ Perform replacements in the configuration file. diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py index 53a3bc8d048..0d65b0cd177 100755 --- a/test/functional/tool_wallet.py +++ b/test/functional/tool_wallet.py @@ -5,7 +5,6 @@ """Test bitcoin-wallet.""" import os -import platform import random import stat import string @@ -536,9 +535,7 @@ class ToolWalletTest(BitcoinTestFramework): # Next cause a bunch of writes by filling the keypool wallet.keypoolrefill(wallet.getwalletinfo()["keypoolsize"] + 100) # Lastly kill bitcoind so that the LSNs don't get reset - self.nodes[0].process.kill() - self.nodes[0].wait_until_stopped(expected_ret_code=1 if platform.system() == "Windows" else -9) - assert self.nodes[0].is_node_stopped() + self.nodes[0].kill_process() wallet_dump = self.nodes[0].datadir_path / "unclean_lsn.dump" self.assert_raises_tool_error("LSNs are not reset, this database is not completely flushed. Please reopen then close the database with a version that has BDB support", "-wallet=unclean_lsn", f"-dumpfile={wallet_dump}", "dump") diff --git a/test/functional/wallet_reorgsrestore.py b/test/functional/wallet_reorgsrestore.py index d9be3bd2e9a..9c69c33680f 100755 --- a/test/functional/wallet_reorgsrestore.py +++ b/test/functional/wallet_reorgsrestore.py @@ -115,7 +115,7 @@ class ReorgsRestoreTest(BitcoinTestFramework): assert_equal(wallet.gettransaction(coinbase_tx_id)['details'][0]['abandoned'], True) # Abort process abruptly to mimic an unclean shutdown (no chain state flush to disk) - node.process.kill() + node.kill_process() # Restart the node and confirm that it has not persisted the last chain state changes to disk self.start_node(0)