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()):

Reply via email to