2
2
# Copyright (c) 2021-present The Bitcoin Core developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
- """Stress tests related to node initialization."""
5
+ """Tests related to node initialization."""
6
6
from pathlib import Path
7
7
import platform
8
8
import shutil
9
9
10
10
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
+ )
12
15
from test_framework .util import assert_equal
13
16
14
17
15
- class InitStressTest (BitcoinTestFramework ):
18
+ class InitTest (BitcoinTestFramework ):
16
19
"""
17
20
Ensure that initialization can be interrupted at a number of points and not impair
18
21
subsequent starts.
@@ -25,7 +28,7 @@ def set_test_params(self):
25
28
self .setup_clean_chain = False
26
29
self .num_nodes = 1
27
30
28
- def run_test (self ):
31
+ def init_stress_test (self ):
29
32
"""
30
33
- test terminating initialization after seeing a certain log line.
31
34
- test removing certain essential files to test startup error paths.
@@ -147,6 +150,31 @@ def check_clean_start():
147
150
shutil .move (node .chain_path / "blocks_bak" , node .chain_path / "blocks" )
148
151
shutil .move (node .chain_path / "chainstate_bak" , node .chain_path / "chainstate" )
149
152
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
+
150
178
151
179
if __name__ == '__main__' :
152
- InitStressTest (__file__ ).main ()
180
+ InitTest (__file__ ).main ()
0 commit comments