Skip to content

Commit b8c821c

Browse files
committed
Merge bitcoin/bitcoin#30724: test: add test for specifying custom pidfile via -pid
04e4d52 test: add test for specifying custom pidfile via `-pid` (Sebastian Falbesoner) b832ffe refactor: introduce default pid file name constant in tests (tdb3) Pull request description: This small PR adds test coverage for the `-pid` command line option, which allows to overrule the pid filename (`bitcoind.pid` by default). One can specify either a relative path (within the datadir) or an absolute one; the latter is tested using `self.options.tmpdir`. Note that the functional test file `feature_init.py` so far only contained a stress test; with this new sub-test added, both the description and the test name are adapted to be more generic. ACKs for top commit: achow101: ACK 04e4d52 tdb3: ACK 04e4d52 ryanofsky: Code review ACK 04e4d52 naiyoma: Tested ACK [https://github.com/bitcoin/bitcoin/pull/30724/commits/04e4d52420a0e6bf40d4bd6fe1f31f66db9eab0a](https://github.com/bitcoin/bitcoin/pull/30724/commits/04e4d52420a0e6bf40d4bd6fe1f31f66db9eab0a) Tree-SHA512: b2bc8a790e5d187e2c84345f344f65a176b62caecd9797c3b9edf10294c741c33a24e535be640b56444b91dcf9c65c7dd152cdffd8b1c1d9ca68e5e3c6ad1e99
2 parents ffe4261 + 04e4d52 commit b8c821c

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

test/functional/feature_filelock.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import string
88

99
from test_framework.test_framework import BitcoinTestFramework
10-
from test_framework.test_node import ErrorMatch
10+
from test_framework.test_node import (
11+
BITCOIN_PID_FILENAME_DEFAULT,
12+
ErrorMatch,
13+
)
1114

1215
class FilelockTest(BitcoinTestFramework):
1316
def add_options(self, parser):
@@ -33,7 +36,7 @@ def run_test(self):
3336
self.log.info("Check that cookie and PID file are not deleted when attempting to start a second bitcoind using the same datadir")
3437
cookie_file = datadir / ".cookie"
3538
assert cookie_file.exists() # should not be deleted during the second bitcoind instance shutdown
36-
pid_file = datadir / "bitcoind.pid"
39+
pid_file = datadir / BITCOIN_PID_FILENAME_DEFAULT
3740
assert pid_file.exists()
3841

3942
if self.is_wallet_compiled():

test/functional/feature_init.py

Lines changed: 33 additions & 5 deletions
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()

test/functional/test_framework/test_node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
NUM_XOR_BYTES = 8
4949
# The null blocks key (all 0s)
5050
NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
51+
BITCOIN_PID_FILENAME_DEFAULT = "bitcoind.pid"
5152

5253

5354
class FailedToStartError(Exception):

0 commit comments

Comments
 (0)