diff options
| author | Sergey Shepelev <temotor@gmail.com> | 2017-01-05 05:08:38 +0300 |
|---|---|---|
| committer | Sergey Shepelev <temotor@gmail.com> | 2017-01-05 05:39:04 +0300 |
| commit | 60e54997f3bb973e408aa6d758befac1a98d60f7 (patch) | |
| tree | 5d9bb51285928949427b90100bd7256831bbb027 /tests/isolated/hub_fork_simple.py | |
| parent | 461348f9a8459724be87c281eea4e0408138a82c (diff) | |
| download | eventlet-next.tar.gz | |
tests cleanup, CI with Python 3.6next
Diffstat (limited to 'tests/isolated/hub_fork_simple.py')
| -rw-r--r-- | tests/isolated/hub_fork_simple.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/isolated/hub_fork_simple.py b/tests/isolated/hub_fork_simple.py new file mode 100644 index 0000000..96389de --- /dev/null +++ b/tests/isolated/hub_fork_simple.py @@ -0,0 +1,58 @@ +import os +import signal +import sys +import tempfile +__test__ = False + + +def parent(signal_path, pid): + eventlet.Timeout(5) + port = None + while True: + try: + contents = open(signal_path, 'rb').read() + port = int(contents.strip()) + break + except Exception: + eventlet.sleep(0.1) + eventlet.connect(('127.0.0.1', port)) + while True: + try: + contents = open(signal_path, 'rb').read() + result = contents.split()[1] + break + except Exception: + eventlet.sleep(0.1) + assert result == b'done', repr(result) + print('pass') + + +def child(signal_path): + eventlet.Timeout(5) + s = eventlet.listen(('127.0.0.1', 0)) + with open(signal_path, 'wb') as f: + f.write(str(s.getsockname()[1]).encode() + b'\n') + f.flush() + s.accept() + f.write(b'done\n') + f.flush() + + +if __name__ == '__main__': + import eventlet + + with tempfile.NamedTemporaryFile() as signal_file: + signal_path = signal_file.name + + pid = os.fork() + if pid < 0: + sys.stderr.write('fork error\n') + sys.exit(1) + elif pid == 0: + child(signal_path) + sys.exit(0) + elif pid > 0: + try: + parent(signal_path, pid) + except Exception: + os.kill(pid, signal.SIGTERM) |
