4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
"""Tests related to node initialization."""
6
6
from pathlib import Path
7
+ import os
7
8
import platform
8
9
import shutil
10
+ import signal
11
+ import subprocess
9
12
10
- from test_framework .test_framework import BitcoinTestFramework , SkipTest
13
+ from test_framework .test_framework import BitcoinTestFramework
11
14
from test_framework .test_node import (
12
15
BITCOIN_PID_FILENAME_DEFAULT ,
13
16
ErrorMatch ,
@@ -33,20 +36,17 @@ def init_stress_test(self):
33
36
- test terminating initialization after seeing a certain log line.
34
37
- test removing certain essential files to test startup error paths.
35
38
"""
36
- # TODO: skip Windows for now since it isn't clear how to SIGTERM.
37
- #
38
- # Windows doesn't support `process.terminate()`.
39
- # and other approaches (like below) don't work:
40
- #
41
- # os.kill(node.process.pid, signal.CTRL_C_EVENT)
42
- if platform .system () == 'Windows' :
43
- raise SkipTest ("can't SIGTERM on Windows" )
44
-
45
39
self .stop_node (0 )
46
40
node = self .nodes [0 ]
47
41
48
42
def sigterm_node ():
49
- node .process .terminate ()
43
+ if platform .system () == 'Windows' :
44
+ # Don't call Python's terminate() since it calls
45
+ # TerminateProcess(), which unlike SIGTERM doesn't allow
46
+ # bitcoind to perform any shutdown logic.
47
+ os .kill (node .process .pid , signal .CTRL_BREAK_EVENT )
48
+ else :
49
+ node .process .terminate ()
50
50
node .process .wait ()
51
51
52
52
def start_expecting_error (err_fragment ):
@@ -86,10 +86,16 @@ def check_clean_start():
86
86
if self .is_wallet_compiled ():
87
87
lines_to_terminate_after .append (b'Verifying wallet' )
88
88
89
+ args = ['-txindex=1' , '-blockfilterindex=1' , '-coinstatsindex=1' ]
89
90
for terminate_line in lines_to_terminate_after :
90
91
self .log .info (f"Starting node and will exit after line { terminate_line } " )
91
92
with node .busy_wait_for_debug_log ([terminate_line ]):
92
- node .start (extra_args = ['-txindex=1' , '-blockfilterindex=1' , '-coinstatsindex=1' ])
93
+ if platform .system () == 'Windows' :
94
+ # CREATE_NEW_PROCESS_GROUP is required in order to be able
95
+ # to terminate the child without terminating the test.
96
+ node .start (extra_args = args , creationflags = subprocess .CREATE_NEW_PROCESS_GROUP )
97
+ else :
98
+ node .start (extra_args = args )
93
99
self .log .debug ("Terminating node after terminate line was found" )
94
100
sigterm_node ()
95
101
0 commit comments