Mercurial > hg
annotate tests/testlib/sigpipe-remote.py @ 47618:27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Instead of using sophisticated logics with thread a non blocking pipes, we
simply spawn two new process in charge of reading the pipe and sending the
result to the client. When it is time to cut the pipe we violently kill them
without any remorse. This close the pipe regardless of any in progress `os.read`
call.
Ironically this is the very same things as what the initial shell setup was
doing, but in Python.
This makes the test pass run properly on Windows. This also reveal that the
Windows behavior is broken as the transaction is not properly rollback. However
this is an adventure for another time. Making the test behave properly was
enough effort.
Differential Revision: https://phab.mercurial-scm.org/D11087
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 12 Jul 2021 03:30:04 +0200 |
parents | d5fc1b59a2df |
children | b2ed9480b34a |
rev | line source |
---|---|
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 |
47617
d5fc1b59a2df
sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47616
diff
changeset
|
4 import io |
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
|
5 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
|
6 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
|
7 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
|
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 |
47617
d5fc1b59a2df
sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47616
diff
changeset
|
12 if isinstance(sys.stdout.buffer, io.BufferedWriter): |
d5fc1b59a2df
sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47616
diff
changeset
|
13 print('SIGPIPE-HELPER: script need unbuffered output', file=sys.stderr) |
d5fc1b59a2df
sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47616
diff
changeset
|
14 sys.exit(255) |
d5fc1b59a2df
sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47616
diff
changeset
|
15 |
47616
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
16 DEBUG_FILE = os.environ.get('SIGPIPE_REMOTE_DEBUG_FILE') |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
17 if DEBUG_FILE is None: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
18 debug_stream = sys.stderr.buffer |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
19 else: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
20 debug_stream = open(DEBUG_FILE, 'bw', buffering=0) |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
21 |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
22 SYNCFILE1 = os.environ.get('SYNCFILE1') |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
23 SYNCFILE2 = os.environ.get('SYNCFILE2') |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
24 if SYNCFILE1 is None: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
25 print('SIGPIPE-HELPER: missing variable $SYNCFILE1', file=sys.stderr) |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
26 sys.exit(255) |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
27 if SYNCFILE2 is None: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
28 print('SIGPIPE-HELPER: missing variable $SYNCFILE2', file=sys.stderr) |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
29 sys.exit(255) |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
30 |
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
|
31 |
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 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
|
33 """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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 |
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 |
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 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 |
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 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
|
51 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
|
52 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
|
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 |
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 # 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
|
56 |
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 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
|
58 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
|
59 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
|
60 |
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 |
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 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
|
63 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
|
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 |
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 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
|
67 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
|
68 |
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 |
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 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
|
71 |
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 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
|
73 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
|
74 |
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 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 ) |
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 |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
82 try: |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
83 cmd = ['hg'] |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
84 cmd += sys.argv[1:] |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
85 sub = subprocess.Popen( |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
86 cmd, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
87 bufsize=0, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
88 close_fds=True, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
89 stdin=sys.stdin, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
90 stdout=subprocess.PIPE, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
91 stderr=subprocess.PIPE, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
92 ) |
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
|
93 |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
94 basedir = os.path.dirname(sys.argv[0]) |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
95 worker = os.path.join(basedir, 'sigpipe-worker.py') |
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
|
96 |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
97 cmd = [sys.executable, worker] |
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
|
98 |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
99 stdout_worker = subprocess.Popen( |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
100 cmd, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
101 bufsize=0, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
102 close_fds=True, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
103 stdin=sub.stdout, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
104 stdout=sys.stdout, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
105 stderr=sys.stderr, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
106 ) |
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
|
107 |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
108 stderr_worker = subprocess.Popen( |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
109 cmd, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
110 bufsize=0, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
111 close_fds=True, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
112 stdin=sub.stderr, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
113 stdout=sys.stderr, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
114 stderr=sys.stderr, |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
115 ) |
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
|
116 debug_stream.write(b'SIGPIPE-HELPER: Redirection in place\n') |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
117 os.close(sub.stdout.fileno()) |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
118 os.close(sub.stderr.fileno()) |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
119 debug_stream.write(b'SIGPIPE-HELPER: pipes closed in main\n') |
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
|
120 |
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 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 debug_stream.write(b'SIGPIPE-HELPER: SYNCFILE1 detected\n') |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
128 stdout_worker.kill() |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
129 stderr_worker.kill() |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
130 stdout_worker.wait(10) |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
131 stderr_worker.wait(10) |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
132 debug_stream.write(b'SIGPIPE-HELPER: worker killed\n') |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
133 |
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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 debug_stream.write(msg) |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
145 sub.kill() |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
146 sub.wait() |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
147 msg = b'SIGPIPE-HELPER: Server process killed\n' |
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
|
148 else: |
47618
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
149 msg = b'SIGPIPE-HELPER: Server process terminated with status %d\n' |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
150 msg %= sub.returncode |
27ff81547d35
sigpipe-remote: simply delegate pipe forwarding to subprocess we can kill
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47617
diff
changeset
|
151 debug_stream.write(msg) |
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
|
152 debug_stream.write(b'SIGPIPE-HELPER: Shut down\n') |