summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-06 01:13:16 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-01-06 01:13:16 +0100
commitb4096a70b09ac7dcd01704bf16ea361257bcae01 (patch)
tree0f745d87c9f5b767c8c247ad04e7061ab9aa4b9b /tests
parent1ff9e5f34beddc511720de05000fb1fcf43e2d80 (diff)
downloadtrollius-b4096a70b09ac7dcd01704bf16ea361257bcae01.tar.gz
Issue #23140: Fix cancellation of Process.wait(). Check the state of the waiter
future before setting its result.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_subprocess.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py
index d82cbbf..dfe23be 100644
--- a/tests/test_subprocess.py
+++ b/tests/test_subprocess.py
@@ -223,6 +223,34 @@ class SubprocessMixin:
self.assertEqual(output.rstrip(), b'3')
self.assertEqual(exitcode, 0)
+ def test_cancel_process_wait(self):
+ # Issue #23140: cancel Process.wait()
+
+ @asyncio.coroutine
+ def wait_proc(proc, event):
+ event.set()
+ yield from proc.wait()
+
+ @asyncio.coroutine
+ def cancel_wait():
+ proc = yield from asyncio.create_subprocess_exec(
+ *PROGRAM_BLOCKED,
+ loop=self.loop)
+
+ # Create an internal future waiting on the process exit
+ event = asyncio.Event(loop=self.loop)
+ task = self.loop.create_task(wait_proc(proc, event))
+ yield from event.wait()
+
+ # Cancel the future
+ task.cancel()
+
+ # Kill the process and wait until it is done
+ proc.kill()
+ yield from proc.wait()
+
+ self.loop.run_until_complete(cancel_wait())
+
if sys.platform != 'win32':
# Unix