tests/testlib/sigpipe-remote.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 19 Jul 2021 06:21:04 +0200
changeset 47669 55c8e0d52eef
parent 47637 d0c0d7b98014
child 48875 6000f5b25c9b
permissions -rwxr-xr-x
dirstate: add a `set_possibly_dirty` in `fakedirstatewritetime` Differential Revision: https://phab.mercurial-scm.org/D11122
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
47636
b2ed9480b34a sigpipe-remote: check for python version earlier in the script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47618
diff changeset
    10
# we cannot use mercurial.testing as long as python2 is not dropped as the test
b2ed9480b34a sigpipe-remote: check for python version earlier in the script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47618
diff changeset
    11
# will only install the mercurial module for python2 in python2 run
b2ed9480b34a sigpipe-remote: check for python version earlier in the script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47618
diff changeset
    12
if sys.version_info[0] < 3:
47637
d0c0d7b98014 sigpipe-remote: display more information about the non-py3 python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47636
diff changeset
    13
    ver = '.'.join(str(x) for x in sys.version_info)
d0c0d7b98014 sigpipe-remote: display more information about the non-py3 python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47636
diff changeset
    14
    exe = sys.executable
47636
b2ed9480b34a sigpipe-remote: check for python version earlier in the script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47618
diff changeset
    15
    print('SIGPIPE-HELPER: script should run with Python 3', file=sys.stderr)
47637
d0c0d7b98014 sigpipe-remote: display more information about the non-py3 python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47636
diff changeset
    16
    print('SIGPIPE-HELPER:   %s is running %s' % (exe, ver), file=sys.stderr)
47636
b2ed9480b34a sigpipe-remote: check for python version earlier in the script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47618
diff changeset
    17
    sys.exit(255)
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
    18
47617
d5fc1b59a2df sigpipe-remote: verify the script is IO are unbuffered
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47616
diff changeset
    19
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
    20
    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
    21
    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
    22
47616
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    23
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
    24
if DEBUG_FILE is None:
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    25
    debug_stream = sys.stderr.buffer
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    26
else:
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    27
    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
    28
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    29
SYNCFILE1 = os.environ.get('SYNCFILE1')
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    30
SYNCFILE2 = os.environ.get('SYNCFILE2')
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    31
if SYNCFILE1 is None:
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    32
    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
    33
    sys.exit(255)
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    34
if SYNCFILE2 is None:
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    35
    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
    36
    sys.exit(255)
df6148ca7120 sigpipe-remote: check environment variable sooner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47557
diff changeset
    37
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
    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 _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
    40
    """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
    41
    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
    42
    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
    43
    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
    44
        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
    45
    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
    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 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
    49
    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
    50
    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
    51
    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
    52
        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
    53
            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
    54
        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
    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
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
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
    58
    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
    59
        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
    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
# 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
    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
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
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
    66
    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
    67
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
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
    70
    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
    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
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
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
    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
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
    76
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
    77
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
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
    79
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
    80
    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
    81
    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
    82
    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
    83
)
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
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
    85
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
    86
    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
    87
    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
    88
    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
    89
        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
    90
        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
    91
        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
    92
        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
    93
        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
    94
        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
    95
    )
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
    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
    98
    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
    99
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
   100
    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
   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
    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
   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.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
   107
        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
   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
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
    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
   112
        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
   113
        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
   114
        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
   115
        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
   116
        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
   117
        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
   118
    )
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
   119
    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
   120
    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
   121
    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
   122
    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
   123
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
    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
   125
        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
   126
    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
   127
        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
   128
        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
   129
    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
   130
        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
   131
    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
   132
    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
   133
    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
   134
    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
   135
    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
   136
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
   137
    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
   138
    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
   139
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
   140
    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
   141
    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
   142
        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
   143
    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
   144
        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
   145
    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
   146
        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
   147
        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
   148
        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
   149
        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
   150
        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
   151
    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
   152
        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
   153
        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
   154
        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
   155
    debug_stream.write(b'SIGPIPE-HELPER: Shut down\n')