Mercurial > hg
annotate tests/testlib/sigpipe-remote.py @ 51281:8f1983318455
common-pattern: cover "elapsed time" line
These are perfect targets for the common-pattern matching.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 13 Dec 2023 13:46:28 +0100 |
parents | 70df51a2c2ce |
children |
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 |
47617
d5fc1b59a2df
sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47616
diff
changeset
|
3 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
|
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 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
|
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
|
9 |
47617
d5fc1b59a2df
sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47616
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 |
47616
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
14 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
|
15 if DEBUG_FILE is None: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
16 debug_stream = sys.stderr.buffer |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
17 else: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
18 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
|
19 |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
20 SYNCFILE1 = os.environ.get('SYNCFILE1') |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
21 SYNCFILE2 = os.environ.get('SYNCFILE2') |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
22 if SYNCFILE1 is None: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
23 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
|
24 sys.exit(255) |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
25 if SYNCFILE2 is None: |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
26 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
|
27 sys.exit(255) |
df6148ca7120
sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47557
diff
changeset
|
28 |
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
|
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 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
|
31 """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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
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 |
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 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
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 |
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 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
|
49 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
|
50 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
|
51 |
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 |
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 # 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
|
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 |
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 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
|
57 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
|
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 |
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 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
|
61 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
|
62 |
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 |
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 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
|
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 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
|
67 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
|
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 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
|
70 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
|
71 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
|
72 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
|
73 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
|
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 |
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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 ) |
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
|
87 |
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
|
88 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
|
89 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
|
90 |
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
|
91 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
|
92 |
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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 ) |
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
|
101 |
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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 ) |
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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 |
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 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 |
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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 debug_stream.write(b'SIGPIPE-HELPER: Shut down\n') |