* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/
@ 2019-04-15 23:15 Zac Medico
0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2019-04-15 23:15 UTC (permalink / raw
To: gentoo-commits
commit: 6055796f5c5a4d69b759b0af376e9388aa5767a7
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 15 23:13:37 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Apr 15 23:15:07 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=6055796f
WakeupFdSigchldTestCase: enable test with python2.7
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
.../tests/util/futures/asyncio/test_wakeup_fd_sigchld.py | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/lib/portage/tests/util/futures/asyncio/test_wakeup_fd_sigchld.py b/lib/portage/tests/util/futures/asyncio/test_wakeup_fd_sigchld.py
index abc67c241..e5b104e0f 100644
--- a/lib/portage/tests/util/futures/asyncio/test_wakeup_fd_sigchld.py
+++ b/lib/portage/tests/util/futures/asyncio/test_wakeup_fd_sigchld.py
@@ -1,4 +1,4 @@
-# Copyright 2018 Gentoo Foundation
+# Copyright 2018-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import os
@@ -7,7 +7,6 @@ import subprocess
import portage
from portage.const import PORTAGE_PYM_PATH
from portage.tests import TestCase
-from portage.util._eventloop.global_event_loop import _asyncio_enabled
class WakeupFdSigchldTestCase(TestCase):
@@ -19,11 +18,8 @@ class WakeupFdSigchldTestCase(TestCase):
Exception ignored when trying to write to the signal wakeup fd:
BlockingIOError: [Errno 11] Resource temporarily unavailable
"""
- if not _asyncio_enabled:
- self.skipTest('asyncio not enabled')
script = """
-import asyncio as _real_asyncio
import os
import signal
import sys
@@ -39,7 +35,7 @@ from portage.util.futures import asyncio
loop = asyncio._wrap_loop()
# Cause the loop to register a child watcher.
-proc = loop.run_until_complete(_real_asyncio.create_subprocess_exec('sleep', '0'))
+proc = loop.run_until_complete(asyncio.create_subprocess_exec('sleep', '0', loop=loop))
loop.run_until_complete(proc.wait())
for i in range(8192):
@@ -47,7 +43,7 @@ for i in range(8192):
# Verify that the child watcher still works correctly
# (this will hang if it doesn't).
-proc = loop.run_until_complete(_real_asyncio.create_subprocess_exec('sleep', '0'))
+proc = loop.run_until_complete(asyncio.create_subprocess_exec('sleep', '0', loop=loop))
loop.run_until_complete(proc.wait())
loop.close()
sys.stdout.write('success')
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/
@ 2019-10-15 0:46 Zac Medico
0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2019-10-15 0:46 UTC (permalink / raw
To: gentoo-commits
commit: e57cc89e8870beff73a65ab4a59fea2fae3c262e
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 15 00:40:55 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Oct 15 00:45:30 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=e57cc89e
ChildWatcherTestCase: python3.8 compat
Since python3.8, the add_child_handler method must be called
while the event loop is running, in order to avoid this error:
File "lib/portage/tests/util/futures/asyncio/test_child_watcher.py", line 41, in testChildWatcher
watcher.add_child_handler(pids[0], callback, *args_tuple)
File "/opt/python/3.8-dev/lib/python3.8/asyncio/unix_events.py", line 1286, in add_child_handler
loop = events.get_running_loop()
RuntimeError: no running event loop
See: https://travis-ci.org/gentoo/portage/jobs/597907096
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
.../tests/util/futures/asyncio/test_child_watcher.py | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/lib/portage/tests/util/futures/asyncio/test_child_watcher.py b/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
index 0fc73ab49..8a8fb3d4f 100644
--- a/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
+++ b/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
@@ -1,4 +1,4 @@
-# Copyright 2018 Gentoo Foundation
+# Copyright 2018-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import os
@@ -7,6 +7,7 @@ from portage.process import find_binary, spawn
from portage.tests import TestCase
from portage.util._eventloop.global_event_loop import global_event_loop
from portage.util.futures import asyncio
+from portage.util.futures.compat_coroutine import coroutine
from portage.util.futures.unix_events import DefaultEventLoopPolicy
@@ -36,13 +37,17 @@ class ChildWatcherTestCase(TestCase):
def callback(pid, returncode, *args):
future.set_result((pid, returncode, args))
- with asyncio.get_child_watcher() as watcher:
- pids = spawn([true_binary], returnpid=True)
- watcher.add_child_handler(pids[0], callback, *args_tuple)
+ @coroutine
+ def watch_pid():
- self.assertEqual(
- loop.run_until_complete(future),
- (pids[0], os.EX_OK, args_tuple))
+ with asyncio.get_child_watcher() as watcher:
+ pids = spawn([true_binary], returnpid=True)
+ watcher.add_child_handler(pids[0], callback, *args_tuple)
+ self.assertEqual(
+ (yield future),
+ (pids[0], os.EX_OK, args_tuple))
+
+ loop.run_until_complete(watch_pid())
finally:
asyncio.set_event_loop_policy(initial_policy)
if loop not in (None, global_event_loop()):
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/
@ 2019-11-16 8:56 Zac Medico
0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2019-11-16 8:56 UTC (permalink / raw
To: gentoo-commits
commit: 40306beadf35659ce6dbe40ffe10c677e6e13918
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 16 08:52:51 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Nov 16 08:54:49 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=40306bea
SubprocessExecTestCase: test pipe between processes
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
.../util/futures/asyncio/test_subprocess_exec.py | 36 ++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py b/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py
index 61646cb92..d7e94d132 100644
--- a/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py
+++ b/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py
@@ -1,4 +1,4 @@
-# Copyright 2018 Gentoo Foundation
+# Copyright 2018-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import os
@@ -10,7 +10,6 @@ from portage.tests import TestCase
from portage.util._eventloop.global_event_loop import global_event_loop
from portage.util.futures import asyncio
from portage.util.futures._asyncio import create_subprocess_exec
-from portage.util.futures._asyncio.streams import _reader as reader
from portage.util.futures.compat_coroutine import coroutine, coroutine_return
from portage.util.futures.unix_events import DefaultEventLoopPolicy
@@ -94,6 +93,39 @@ class SubprocessExecTestCase(TestCase):
self._run_test(test)
+ def testPipe(self):
+ stdin_data = b'hello world'
+ cat_binary = find_binary("cat")
+ self.assertNotEqual(cat_binary, None)
+ cat_binary = cat_binary.encode()
+
+ echo_binary = find_binary("echo")
+ self.assertNotEqual(echo_binary, None)
+ echo_binary = echo_binary.encode()
+
+ def test(loop):
+
+ pr, pw = os.pipe()
+
+ cat_proc = loop.run_until_complete(create_subprocess_exec(
+ cat_binary, stdin=pr, stdout=subprocess.PIPE,
+ loop=loop))
+
+ echo_proc = loop.run_until_complete(create_subprocess_exec(
+ echo_binary, b'-n', stdin_data, stdout=pw,
+ loop=loop))
+
+ os.close(pr)
+ os.close(pw)
+
+ out, err = loop.run_until_complete(cat_proc.communicate())
+
+ self.assertEqual(loop.run_until_complete(cat_proc.wait()), os.EX_OK)
+ self.assertEqual(loop.run_until_complete(echo_proc.wait()), os.EX_OK)
+ self.assertEqual(out, stdin_data)
+
+ self._run_test(test)
+
def testReadTransport(self):
"""
Test asyncio.create_subprocess_exec(stdout=subprocess.PIPE) which
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/
@ 2020-08-08 3:04 Zac Medico
0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2020-08-08 3:04 UTC (permalink / raw
To: gentoo-commits
commit: 570faa2a3bd095e4ec86abcf85df3c79a0b418cf
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Aug 8 03:01:35 2020 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Aug 8 03:03:02 2020 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=570faa2a
EventLoopInForkTestCase: use AsyncFunction
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
.../futures/asyncio/test_event_loop_in_fork.py | 23 +++++-----------------
1 file changed, 5 insertions(+), 18 deletions(-)
diff --git a/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py b/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py
index 177953437..e409fd52b 100644
--- a/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py
+++ b/lib/portage/tests/util/futures/asyncio/test_event_loop_in_fork.py
@@ -1,17 +1,16 @@
-# Copyright 2018 Gentoo Foundation
+# Copyright 2018-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-import multiprocessing
import os
from portage.tests import TestCase
+from portage.util._async.AsyncFunction import AsyncFunction
from portage.util._eventloop.global_event_loop import global_event_loop
from portage.util.futures import asyncio
from portage.util.futures.unix_events import DefaultEventLoopPolicy
-def fork_main(parent_conn, child_conn):
- parent_conn.close()
+def fork_main():
loop = asyncio._wrap_loop()
# This fails with python's default event loop policy,
# see https://bugs.python.org/issue22087.
@@ -21,21 +20,9 @@ def fork_main(parent_conn, child_conn):
def async_main(fork_exitcode, loop=None):
loop = asyncio._wrap_loop(loop)
-
- # Since python2.7 does not support Process.sentinel, use Pipe to
- # monitor for process exit.
- parent_conn, child_conn = multiprocessing.Pipe()
-
- def eof_callback(proc):
- loop.remove_reader(parent_conn.fileno())
- parent_conn.close()
- proc.join()
- fork_exitcode.set_result(proc.exitcode)
-
- proc = multiprocessing.Process(target=fork_main, args=(parent_conn, child_conn))
- loop.add_reader(parent_conn.fileno(), eof_callback, proc)
+ proc = AsyncFunction(scheduler=loop, target=fork_main)
proc.start()
- child_conn.close()
+ proc.async_wait().add_done_callback(lambda future: fork_exitcode.set_result(future.result()))
class EventLoopInForkTestCase(TestCase):
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/
@ 2021-01-18 12:20 Zac Medico
0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2021-01-18 12:20 UTC (permalink / raw
To: gentoo-commits
commit: 9e6914ffe118457afbd29f448d99052d90e5e3dd
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 18 12:04:02 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 12:04:25 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=9e6914ff
SubprocessExecTestCase: Use async and await syntax
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
.../util/futures/asyncio/test_subprocess_exec.py | 32 ++++++++++------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py b/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py
index 6128a7d06..f9e35f6d4 100644
--- a/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py
+++ b/lib/portage/tests/util/futures/asyncio/test_subprocess_exec.py
@@ -1,4 +1,4 @@
-# Copyright 2018-2019 Gentoo Authors
+# Copyright 2018-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import os
@@ -9,7 +9,6 @@ from portage.tests import TestCase
from portage.util._eventloop.global_event_loop import global_event_loop
from portage.util.futures import asyncio
from portage.util.futures._asyncio import create_subprocess_exec
-from portage.util.futures.compat_coroutine import coroutine, coroutine_return
from portage.util.futures.unix_events import DefaultEventLoopPolicy
@@ -35,41 +34,38 @@ class SubprocessExecTestCase(TestCase):
echo_binary = echo_binary.encode()
def test(loop):
- @coroutine
- def test_coroutine(loop=None):
- proc = (yield create_subprocess_exec(echo_binary, *args_tuple,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- loop=loop))
+ async def test_coroutine():
- out, err = (yield proc.communicate())
+ proc = await create_subprocess_exec(echo_binary, *args_tuple,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+ out, err = await proc.communicate()
self.assertEqual(tuple(out.split()), args_tuple)
self.assertEqual(proc.returncode, os.EX_OK)
- proc = (yield create_subprocess_exec(
+ proc = await create_subprocess_exec(
'bash', '-c', 'echo foo; echo bar 1>&2;',
- stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- loop=loop))
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = (yield proc.communicate())
+ out, err = await proc.communicate()
self.assertEqual(out, b'foo\n')
self.assertEqual(err, b'bar\n')
self.assertEqual(proc.returncode, os.EX_OK)
- proc = (yield create_subprocess_exec(
+ proc = await create_subprocess_exec(
'bash', '-c', 'echo foo; echo bar 1>&2;',
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- loop=loop))
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- out, err = (yield proc.communicate())
+ out, err = await proc.communicate()
self.assertEqual(out, b'foo\nbar\n')
self.assertEqual(err, None)
self.assertEqual(proc.returncode, os.EX_OK)
- coroutine_return('success')
+ return 'success'
self.assertEqual('success',
- loop.run_until_complete(test_coroutine(loop=loop)))
+ loop.run_until_complete(test_coroutine()))
self._run_test(test)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/
@ 2021-01-18 12:20 Zac Medico
0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2021-01-18 12:20 UTC (permalink / raw
To: gentoo-commits
commit: 447ce6fa4a081ff416431a00a43827f67468b015
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 18 11:56:16 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 11:56:42 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=447ce6fa
ChildWatcherTestCase: Use async and await syntax
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/util/futures/asyncio/test_child_watcher.py | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/portage/tests/util/futures/asyncio/test_child_watcher.py b/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
index cd547f008..4e7b4fd7f 100644
--- a/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
+++ b/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
@@ -1,4 +1,4 @@
-# Copyright 2018-2019 Gentoo Authors
+# Copyright 2018-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import os
@@ -7,7 +7,6 @@ from portage.process import find_binary, spawn
from portage.tests import TestCase
from portage.util._eventloop.global_event_loop import global_event_loop
from portage.util.futures import asyncio
-from portage.util.futures.compat_coroutine import coroutine
from portage.util.futures.unix_events import DefaultEventLoopPolicy
@@ -37,17 +36,16 @@ class ChildWatcherTestCase(TestCase):
def callback(pid, returncode, *args):
future.set_result((pid, returncode, args))
- @coroutine
- def watch_pid(loop=None):
+ async def watch_pid():
with asyncio.get_child_watcher() as watcher:
pids = spawn([true_binary], returnpid=True)
watcher.add_child_handler(pids[0], callback, *args_tuple)
self.assertEqual(
- (yield future),
+ (await future),
(pids[0], os.EX_OK, args_tuple))
- loop.run_until_complete(watch_pid(loop=loop))
+ loop.run_until_complete(watch_pid())
finally:
asyncio.set_event_loop_policy(initial_policy)
if loop not in (None, global_event_loop()):
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/
@ 2024-02-07 0:36 Zac Medico
0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2024-02-07 0:36 UTC (permalink / raw
To: gentoo-commits
commit: 66d8f8388e5b9da7e07510f78ec487913e2ceaf5
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 4 00:16:29 2024 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Feb 7 00:36:17 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=66d8f838
ChildWatcherTestCase: Remove obsolete test which uses spawn returnpid
This test was added for bug 649588 when there was still an
internal event loop implementation for python2. It is no
longer relevant and uses the deprecated spawn returnpid
parameter, so remove it.
Bug: https://bugs.gentoo.org/916566
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/util/futures/asyncio/meson.build | 1 -
.../util/futures/asyncio/test_child_watcher.py | 50 ----------------------
2 files changed, 51 deletions(-)
diff --git a/lib/portage/tests/util/futures/asyncio/meson.build b/lib/portage/tests/util/futures/asyncio/meson.build
index ba727052fc..2de0668d6b 100644
--- a/lib/portage/tests/util/futures/asyncio/meson.build
+++ b/lib/portage/tests/util/futures/asyncio/meson.build
@@ -1,6 +1,5 @@
py.install_sources(
[
- 'test_child_watcher.py',
'test_event_loop_in_fork.py',
'test_pipe_closed.py',
'test_policy_wrapper_recursion.py',
diff --git a/lib/portage/tests/util/futures/asyncio/test_child_watcher.py b/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
deleted file mode 100644
index cd100598b7..0000000000
--- a/lib/portage/tests/util/futures/asyncio/test_child_watcher.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# Copyright 2018-2021 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-import os
-
-from portage.process import find_binary, spawn
-from portage.tests import TestCase
-from portage.util._eventloop.global_event_loop import global_event_loop
-from portage.util.futures import asyncio
-from portage.util.futures.unix_events import DefaultEventLoopPolicy
-
-
-class ChildWatcherTestCase(TestCase):
- def testChildWatcher(self):
- true_binary = find_binary("true")
- self.assertNotEqual(true_binary, None)
-
- initial_policy = asyncio.get_event_loop_policy()
- if not isinstance(initial_policy, DefaultEventLoopPolicy):
- asyncio.set_event_loop_policy(DefaultEventLoopPolicy())
-
- loop = None
- try:
- try:
- asyncio.set_child_watcher(None)
- except NotImplementedError:
- pass
- else:
- self.assertTrue(False)
-
- args_tuple = ("hello", "world")
-
- loop = asyncio._wrap_loop()
- future = loop.create_future()
-
- def callback(pid, returncode, *args):
- future.set_result((pid, returncode, args))
-
- async def watch_pid():
- with asyncio.get_child_watcher() as watcher:
- pids = spawn([true_binary], returnpid=True)
- watcher.add_child_handler(pids[0], callback, *args_tuple)
- self.assertEqual((await future), (pids[0], os.EX_OK, args_tuple))
-
- loop.run_until_complete(watch_pid())
- finally:
- asyncio.set_event_loop_policy(initial_policy)
- if loop not in (None, global_event_loop()):
- loop.close()
- self.assertFalse(global_event_loop().is_closed())
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-02-07 0:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-07 0:36 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/futures/asyncio/ Zac Medico
-- strict thread matches above, loose matches on Subject: below --
2021-01-18 12:20 Zac Medico
2021-01-18 12:20 Zac Medico
2020-08-08 3:04 Zac Medico
2019-11-16 8:56 Zac Medico
2019-10-15 0:46 Zac Medico
2019-04-15 23:15 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox