summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_subprocess.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-17 21:49:11 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-17 21:49:11 (GMT)
commit98fa332e334633d5559ff3963df0ab5c6108d8e1 (patch)
tree649e60421b9ecc111b4157bc39af0f91df0db951 /Lib/test/test_asyncio/test_subprocess.py
parentfe5649c7b7bf52147480d6b1124a3d8e3597aee3 (diff)
downloadcpython-98fa332e334633d5559ff3963df0ab5c6108d8e1.zip
cpython-98fa332e334633d5559ff3963df0ab5c6108d8e1.tar.gz
cpython-98fa332e334633d5559ff3963df0ab5c6108d8e1.tar.bz2
Issue #21247: Fix a race condition in test_send_signal() of asyncio
Add a basic synchronization mechanism to wait until the child process is ready before sending it a signal.
Diffstat (limited to 'Lib/test/test_asyncio/test_subprocess.py')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index d050458..5425d9b 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -108,11 +108,22 @@ class SubprocessMixin:
@unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
def test_send_signal(self):
- args = PROGRAM_BLOCKED
- create = asyncio.create_subprocess_exec(*args, loop=self.loop)
+ code = 'import time; print("sleeping", flush=True); time.sleep(3600)'
+ args = [sys.executable, '-c', code]
+ create = asyncio.create_subprocess_exec(*args, loop=self.loop, stdout=subprocess.PIPE)
proc = self.loop.run_until_complete(create)
- proc.send_signal(signal.SIGHUP)
- returncode = self.loop.run_until_complete(proc.wait())
+
+ @asyncio.coroutine
+ def send_signal(proc):
+ # basic synchronization to wait until the program is sleeping
+ line = yield from proc.stdout.readline()
+ self.assertEqual(line, b'sleeping\n')
+
+ proc.send_signal(signal.SIGHUP)
+ returncode = (yield from proc.wait())
+ return returncode
+
+ returncode = self.loop.run_until_complete(send_signal(proc))
self.assertEqual(-signal.SIGHUP, returncode)
def prepare_broken_pipe_test(self):