author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Fri, 02 Jul 2021 20:20:37 +0200 | |
changeset 47557 | ed81f2be5527 |
child 47616 | df6148ca7120 |
permissions | -rwxr-xr-x |
47557
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
from __future__ import print_function |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
import os |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
import subprocess |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
import sys |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
import threading |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
import time |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
# we cannot use mercurial.testing as long as python2 is not dropped as the test will only install the mercurial module for python2 in python2 run |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
def _timeout_factor(): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
"""return the current modification to timeout""" |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
default = int(os.environ.get('HGTEST_TIMEOUT_DEFAULT', 360)) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
current = int(os.environ.get('HGTEST_TIMEOUT', default)) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
if current == 0: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
return 1 |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
return current / float(default) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
def wait_file(path, timeout=10): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
timeout *= _timeout_factor() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 |
start = time.time() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 |
while not os.path.exists(path): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 |
if (time.time() - start) > timeout: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
raise RuntimeError(b"timed out waiting for file: %s" % path) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
time.sleep(0.01) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 |
def write_file(path, content=b''): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 |
with open(path, 'wb') as f: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
f.write(content) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 |
# end of mercurial.testing content |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 |
if sys.version_info[0] < 3: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 |
print('SIGPIPE-HELPER: script should run with Python 3', file=sys.stderr) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 |
sys.exit(255) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
43 |
def sysbytes(s): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
44 |
return s.encode('utf-8') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
45 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 |
def sysstr(s): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 |
return s.decode('latin-1') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
49 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 |
piped_stdout = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
52 |
piped_stderr = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 |
stdout_writer = os.fdopen(piped_stdout[1], "rb") |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 |
stdout_reader = os.fdopen(piped_stdout[0], "rb") |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 |
stderr_writer = os.fdopen(piped_stderr[1], "rb") |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
57 |
stderr_reader = os.fdopen(piped_stderr[0], "rb") |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
58 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 |
DEBUG_FILE = os.environ.get('SIGPIPE_REMOTE_DEBUG_FILE') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 |
if DEBUG_FILE is None: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
61 |
debug_stream = sys.stderr.buffer |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
62 |
else: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 |
debug_stream = open(DEBUG_FILE, 'bw', buffering=0) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 |
SYNCFILE1 = os.environ.get('SYNCFILE1') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 |
SYNCFILE2 = os.environ.get('SYNCFILE2') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 |
if SYNCFILE1 is None: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
68 |
print('SIGPIPE-HELPER: missing variable $SYNCFILE1', file=sys.stderr) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 |
sys.exit(255) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 |
if SYNCFILE2 is None: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
71 |
print('SIGPIPE-HELPER: missing variable $SYNCFILE2', file=sys.stderr) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
72 |
sys.exit(255) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
73 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 |
debug_stream.write(b'SIGPIPE-HELPER: Starting\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 |
TESTLIB_DIR = os.path.dirname(sys.argv[0]) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 |
WAIT_SCRIPT = os.path.join(TESTLIB_DIR, 'wait-on-file') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 |
hooks_cmd = '%s 10 %s %s' |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 |
hooks_cmd %= ( |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
81 |
WAIT_SCRIPT, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 |
SYNCFILE2, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
SYNCFILE1, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 |
) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 |
cmd = ['hg'] |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 |
cmd += sys.argv[1:] |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 |
sub = subprocess.Popen( |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 |
cmd, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
90 |
bufsize=0, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
91 |
close_fds=True, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
92 |
stdin=sys.stdin, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
stdout=stdout_writer, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
94 |
stderr=stderr_writer, |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 |
) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
97 |
debug_stream.write(b'SIGPIPE-HELPER: Mercurial started\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
98 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
99 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 |
shut_down = threading.Event() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 |
close_lock = threading.Lock() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
105 |
def _read(stream): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 |
try: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 |
return stream.read() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 |
except ValueError: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
109 |
# read on closed file |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 |
return None |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
111 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
112 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 |
def forward_stdout(): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
114 |
while not shut_down.is_set(): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
115 |
c = _read(stdout_reader) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 |
while c is not None: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 |
sys.stdout.buffer.write(c) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 |
c = _read(stdout_reader) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 |
time.sleep(0.001) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 |
with close_lock: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 |
if not stdout_reader.closed: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 |
stdout_reader.close() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 |
debug_stream.write(b'SIGPIPE-HELPER: stdout closed\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
124 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 |
def forward_stderr(): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
127 |
while not shut_down.is_set(): |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 |
c = _read(stderr_reader) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
129 |
if c is not None: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
130 |
sys.stderr.buffer.write(c) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
131 |
c = _read(stderr_reader) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
132 |
time.sleep(0.001) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
133 |
with close_lock: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
134 |
if not stderr_reader.closed: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
135 |
stderr_reader.close() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
136 |
debug_stream.write(b'SIGPIPE-HELPER: stderr closed\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
137 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
138 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 |
stdout_thread = threading.Thread(target=forward_stdout, daemon=True) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 |
stderr_thread = threading.Thread(target=forward_stderr, daemon=True) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
142 |
try: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 |
stdout_thread.start() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 |
stderr_thread.start() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
146 |
debug_stream.write(b'SIGPIPE-HELPER: Redirection in place\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
147 |
|
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 |
try: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 |
wait_file(sysbytes(SYNCFILE1)) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
150 |
except RuntimeError as exc: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
151 |
msg = sysbytes(str(exc)) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 |
debug_stream.write(b'SIGPIPE-HELPER: wait failed: %s\n' % msg) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
153 |
else: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
154 |
debug_stream.write(b'SIGPIPE-HELPER: SYNCFILE1 detected\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
155 |
with close_lock: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
156 |
if not stdout_reader.closed: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
157 |
stdout_reader.close() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
158 |
if not stderr_reader.closed: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
159 |
stderr_reader.close() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
160 |
sys.stdin.close() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 |
debug_stream.write(b'SIGPIPE-HELPER: pipes closed\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
162 |
debug_stream.write(b'SIGPIPE-HELPER: creating SYNCFILE2\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 |
write_file(sysbytes(SYNCFILE2)) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
164 |
finally: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
165 |
debug_stream.write(b'SIGPIPE-HELPER: Shutting down\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
166 |
shut_down.set() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
167 |
if not sys.stdin.closed: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
168 |
sys.stdin.close() |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
169 |
try: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
170 |
sub.wait(timeout=30) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
171 |
except subprocess.TimeoutExpired: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
172 |
msg = b'SIGPIPE-HELPER: Server process failed to terminate\n' |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
173 |
debug_stream.write(msg) |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
174 |
else: |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
175 |
debug_stream.write(b'SIGPIPE-HELPER: Server process terminated\n') |
ed81f2be5527
test: use a python script in `test-transaction-rollback-on-sigpipe.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
176 |
debug_stream.write(b'SIGPIPE-HELPER: Shut down\n') |