Skip to content

Commit 04e4d52

Browse files
committed
test: add test for specifying custom pidfile via -pid
1 parent b832ffe commit 04e4d52

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

test/functional/feature_init.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
# Copyright (c) 2021-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Stress tests related to node initialization."""
5+
"""Tests related to node initialization."""
66
from pathlib import Path
77
import platform
88
import shutil
99

1010
from test_framework.test_framework import BitcoinTestFramework, SkipTest
11-
from test_framework.test_node import ErrorMatch
11+
from test_framework.test_node import (
12+
BITCOIN_PID_FILENAME_DEFAULT,
13+
ErrorMatch,
14+
)
1215
from test_framework.util import assert_equal
1316

1417

15-
class InitStressTest(BitcoinTestFramework):
18+
class InitTest(BitcoinTestFramework):
1619
"""
1720
Ensure that initialization can be interrupted at a number of points and not impair
1821
subsequent starts.
@@ -25,7 +28,7 @@ def set_test_params(self):
2528
self.setup_clean_chain = False
2629
self.num_nodes = 1
2730

28-
def run_test(self):
31+
def init_stress_test(self):
2932
"""
3033
- test terminating initialization after seeing a certain log line.
3134
- test removing certain essential files to test startup error paths.
@@ -147,6 +150,31 @@ def check_clean_start():
147150
shutil.move(node.chain_path / "blocks_bak", node.chain_path / "blocks")
148151
shutil.move(node.chain_path / "chainstate_bak", node.chain_path / "chainstate")
149152

153+
def init_pid_test(self):
154+
BITCOIN_PID_FILENAME_CUSTOM = "my_fancy_bitcoin_pid_file.foobar"
155+
156+
self.log.info("Test specifying custom pid file via -pid command line option")
157+
custom_pidfile_relative = BITCOIN_PID_FILENAME_CUSTOM
158+
self.log.info(f"-> path relative to datadir ({custom_pidfile_relative})")
159+
self.restart_node(0, [f"-pid={custom_pidfile_relative}"])
160+
datadir = self.nodes[0].chain_path
161+
assert not (datadir / BITCOIN_PID_FILENAME_DEFAULT).exists()
162+
assert (datadir / custom_pidfile_relative).exists()
163+
self.stop_node(0)
164+
assert not (datadir / custom_pidfile_relative).exists()
165+
166+
custom_pidfile_absolute = Path(self.options.tmpdir) / BITCOIN_PID_FILENAME_CUSTOM
167+
self.log.info(f"-> absolute path ({custom_pidfile_absolute})")
168+
self.restart_node(0, [f"-pid={custom_pidfile_absolute}"])
169+
assert not (datadir / BITCOIN_PID_FILENAME_DEFAULT).exists()
170+
assert custom_pidfile_absolute.exists()
171+
self.stop_node(0)
172+
assert not custom_pidfile_absolute.exists()
173+
174+
def run_test(self):
175+
self.init_pid_test()
176+
self.init_stress_test()
177+
150178

151179
if __name__ == '__main__':
152-
InitStressTest(__file__).main()
180+
InitTest(__file__).main()

0 commit comments

Comments
 (0)