From 04e4d52420a0e6bf40d4bd6fe1f31f66db9eab0a Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 27 Aug 2024 14:16:24 +0200 Subject: [PATCH] test: add test for specifying custom pidfile via `-pid` --- test/functional/feature_init.py | 38 ++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/test/functional/feature_init.py b/test/functional/feature_init.py index 659d33684e5..ff3a9391b86 100755 --- a/test/functional/feature_init.py +++ b/test/functional/feature_init.py @@ -2,17 +2,20 @@ # Copyright (c) 2021-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -"""Stress tests related to node initialization.""" +"""Tests related to node initialization.""" from pathlib import Path import platform import shutil from test_framework.test_framework import BitcoinTestFramework, SkipTest -from test_framework.test_node import ErrorMatch +from test_framework.test_node import ( + BITCOIN_PID_FILENAME_DEFAULT, + ErrorMatch, +) from test_framework.util import assert_equal -class InitStressTest(BitcoinTestFramework): +class InitTest(BitcoinTestFramework): """ Ensure that initialization can be interrupted at a number of points and not impair subsequent starts. @@ -25,7 +28,7 @@ def set_test_params(self): self.setup_clean_chain = False self.num_nodes = 1 - def run_test(self): + def init_stress_test(self): """ - test terminating initialization after seeing a certain log line. - test removing certain essential files to test startup error paths. @@ -147,6 +150,31 @@ def check_clean_start(): shutil.move(node.chain_path / "blocks_bak", node.chain_path / "blocks") shutil.move(node.chain_path / "chainstate_bak", node.chain_path / "chainstate") + def init_pid_test(self): + BITCOIN_PID_FILENAME_CUSTOM = "my_fancy_bitcoin_pid_file.foobar" + + self.log.info("Test specifying custom pid file via -pid command line option") + custom_pidfile_relative = BITCOIN_PID_FILENAME_CUSTOM + self.log.info(f"-> path relative to datadir ({custom_pidfile_relative})") + self.restart_node(0, [f"-pid={custom_pidfile_relative}"]) + datadir = self.nodes[0].chain_path + assert not (datadir / BITCOIN_PID_FILENAME_DEFAULT).exists() + assert (datadir / custom_pidfile_relative).exists() + self.stop_node(0) + assert not (datadir / custom_pidfile_relative).exists() + + custom_pidfile_absolute = Path(self.options.tmpdir) / BITCOIN_PID_FILENAME_CUSTOM + self.log.info(f"-> absolute path ({custom_pidfile_absolute})") + self.restart_node(0, [f"-pid={custom_pidfile_absolute}"]) + assert not (datadir / BITCOIN_PID_FILENAME_DEFAULT).exists() + assert custom_pidfile_absolute.exists() + self.stop_node(0) + assert not custom_pidfile_absolute.exists() + + def run_test(self): + self.init_pid_test() + self.init_stress_test() + if __name__ == '__main__': - InitStressTest(__file__).main() + InitTest(__file__).main()