Merge pull request #24326 from gnossen/fix_fork_interop

Remove uses of PIPE in Fork Interop Tests
pull/24360/head
Richard Belleville 4 years ago committed by GitHub
commit 9c41697873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      src/python/grpcio_tests/tests/fork/_fork_interop_test.py
  2. 3
      src/python/grpcio_tests/tests/fork/methods.py

@ -16,6 +16,7 @@
import six
import subprocess
import sys
import tempfile
import threading
import unittest
from grpc._cython import cygrpc
@ -69,15 +70,23 @@ class ForkInteropTest(unittest.TestCase):
while True:
time.sleep(1)
"""
streams = tuple(tempfile.TemporaryFile() for _ in range(2))
self._server_process = subprocess.Popen(
[sys.executable, '-c', start_server_script],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout=streams[0],
stderr=streams[1])
timer = threading.Timer(_SUBPROCESS_TIMEOUT_S,
self._server_process.kill)
try:
timer.start()
self._port = int(self._server_process.stdout.readline())
while True:
streams[0].seek(0)
s = streams[0].readline()
if not s:
continue
else:
self._port = int(s)
break
except ValueError:
raise Exception('Failed to get port from server')
finally:
@ -125,26 +134,22 @@ class ForkInteropTest(unittest.TestCase):
def _verifyTestCase(self, test_case):
script = _CLIENT_FORK_SCRIPT_TEMPLATE % (test_case.name, self._port)
streams = tuple(tempfile.TemporaryFile() for _ in range(2))
process = subprocess.Popen([sys.executable, '-c', script],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout=streams[0],
stderr=streams[1])
timer = threading.Timer(_SUBPROCESS_TIMEOUT_S, process.kill)
try:
timer.start()
try:
out, err = process.communicate(timeout=_SUBPROCESS_TIMEOUT_S)
except TypeError:
# The timeout parameter was added in Python 3.3.
out, err = process.communicate()
except subprocess.TimeoutExpired:
process.kill()
raise RuntimeError('Process failed to terminate')
finally:
timer.cancel()
timer.start()
process.wait()
timer.cancel()
outputs = []
for stream in streams:
stream.seek(0)
outputs.append(stream.read())
self.assertEqual(
0, process.returncode,
'process failed with exit code %d (stdout: %s, stderr: %s)' %
(process.returncode, out, err))
'process failed with exit code %d (stdout: "%s", stderr: "%s")' %
(process.returncode, outputs[0], outputs[1]))
if __name__ == '__main__':

@ -142,7 +142,8 @@ class _ChildProcess(object):
self._process.exitcode)
try:
exception = self._exceptions.get(block=False)
raise ValueError('Child process failed: %s' % exception)
raise ValueError('Child process failed: "%s": "%s"' %
(repr(exception), exception))
except queue.Empty:
pass

Loading…
Cancel
Save