summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-11-22 01:47:08 +0100
committerVictor Stinner <victor.stinner@gmail.com>2014-11-22 01:47:08 +0100
commitd26183452f1e00fac38ad28d3817803605f884d6 (patch)
treeb6829a1acb94630f0501a385dec57275d5a59e29
parent469de722a85bb08cc665ebd60c6cc0385d0c4ae9 (diff)
downloadaioeventlet-d26183452f1e00fac38ad28d3817803605f884d6.tar.gz
link_future() only accepts coroutine objects, not coroutine functions
-rw-r--r--aiogreen.py2
-rw-r--r--doc/using.rst2
-rw-r--r--tests/test_eventlet.py17
3 files changed, 19 insertions, 2 deletions
diff --git a/aiogreen.py b/aiogreen.py
index f1ec37c..45b4ac4 100644
--- a/aiogreen.py
+++ b/aiogreen.py
@@ -301,7 +301,7 @@ def wrap_greenthread(gt, loop=None):
def link_future(future, loop=None):
- """Wait for a future, a task, or a coroutine from a greenthread.
+ """Wait for a future, a task, or a coroutine object from a greenthread.
Return the result or raise the exception of the future.
diff --git a/doc/using.rst b/doc/using.rst
index 5fcf043..0956085 100644
--- a/doc/using.rst
+++ b/doc/using.rst
@@ -115,7 +115,7 @@ link_future
.. function:: link_future(future, loop=None)
- Wait for a future, a task, or a coroutine from a greenthread.
+ Wait for a future, a task, or a coroutine object from a greenthread.
Return the result or raise the exception of the future.
diff --git a/tests/test_eventlet.py b/tests/test_eventlet.py
index 2361e81..4a8970c 100644
--- a/tests/test_eventlet.py
+++ b/tests/test_eventlet.py
@@ -234,6 +234,23 @@ class LinkFutureTests(tests.TestCase):
self.loop.run_forever()
self.assertEqual(result, ['error'])
+ def test_link_future_invalid_type(self):
+ def func(obj):
+ return aiogreen.link_future(obj)
+
+ @asyncio.coroutine
+ def coro_func():
+ print("do something")
+
+ def regular_func():
+ return 3
+
+ for obj in (coro_func, regular_func):
+ gt = eventlet.spawn(func, coro_func)
+ # ignore logged traceback
+ with tests.mock.patch('traceback.print_exception') as m_print:
+ self.assertRaises(TypeError, gt.wait)
+
def test_link_future_wrong_loop(self):
result = []
loop2 = asyncio.new_event_loop()