Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9ab3b215
Commit
9ab3b215
authored
Nov 13, 2015
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Plain Diff
Merge 3.4
parents
f76b9b8c
8cff6dc8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
14 deletions
+18
-14
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+18
-14
No files found.
Lib/test/test_asyncio/test_tasks.py
View file @
9ab3b215
...
@@ -2101,20 +2101,16 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
...
@@ -2101,20 +2101,16 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
class
RunCoroutineThreadsafeTests
(
test_utils
.
TestCase
):
class
RunCoroutineThreadsafeTests
(
test_utils
.
TestCase
):
"""Test case for
futures.submit_to_loop
."""
"""Test case for
asyncio.run_coroutine_threadsafe
."""
def
setUp
(
self
):
def
setUp
(
self
):
self
.
loop
=
self
.
new_test_loop
(
self
.
time_gen
)
self
.
loop
=
asyncio
.
new_event_loop
()
self
.
set_event_loop
(
self
.
loop
)
# Will cleanup properly
def
time_gen
(
self
):
"""Handle the timer."""
yield
0
# second
yield
1
# second
@
asyncio
.
coroutine
@
asyncio
.
coroutine
def
add
(
self
,
a
,
b
,
fail
=
False
,
cancel
=
False
):
def
add
(
self
,
a
,
b
,
fail
=
False
,
cancel
=
False
):
"""Wait
1
second and return a + b."""
"""Wait
0.05
second and return a + b."""
yield
from
asyncio
.
sleep
(
1
,
loop
=
self
.
loop
)
yield
from
asyncio
.
sleep
(
0.05
,
loop
=
self
.
loop
)
if
fail
:
if
fail
:
raise
RuntimeError
(
"Fail!"
)
raise
RuntimeError
(
"Fail!"
)
if
cancel
:
if
cancel
:
...
@@ -2122,10 +2118,20 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
...
@@ -2122,10 +2118,20 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
yield
yield
return
a
+
b
return
a
+
b
def
target
(
self
,
fail
=
False
,
cancel
=
False
,
timeout
=
None
):
def
target
(
self
,
fail
=
False
,
cancel
=
False
,
timeout
=
None
,
advance_coro
=
False
):
"""Run add coroutine in the event loop."""
"""Run add coroutine in the event loop."""
coro
=
self
.
add
(
1
,
2
,
fail
=
fail
,
cancel
=
cancel
)
coro
=
self
.
add
(
1
,
2
,
fail
=
fail
,
cancel
=
cancel
)
future
=
asyncio
.
run_coroutine_threadsafe
(
coro
,
self
.
loop
)
future
=
asyncio
.
run_coroutine_threadsafe
(
coro
,
self
.
loop
)
if
advance_coro
:
# this is for test_run_coroutine_threadsafe_task_factory_exception;
# otherwise it spills errors and breaks **other** unittests, since
# 'target' is interacting with threads.
# With this call, `coro` will be advanced, so that
# CoroWrapper.__del__ won't do anything when asyncio tests run
# in debug mode.
self
.
loop
.
call_soon_threadsafe
(
coro
.
send
,
None
)
try
:
try
:
return
future
.
result
(
timeout
)
return
future
.
result
(
timeout
)
finally
:
finally
:
...
@@ -2152,7 +2158,6 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
...
@@ -2152,7 +2158,6 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
future
=
self
.
loop
.
run_in_executor
(
None
,
callback
)
future
=
self
.
loop
.
run_in_executor
(
None
,
callback
)
with
self
.
assertRaises
(
asyncio
.
TimeoutError
):
with
self
.
assertRaises
(
asyncio
.
TimeoutError
):
self
.
loop
.
run_until_complete
(
future
)
self
.
loop
.
run_until_complete
(
future
)
# Clear the time generator and tasks
test_utils
.
run_briefly
(
self
.
loop
)
test_utils
.
run_briefly
(
self
.
loop
)
# Check that there's no pending task (add has been cancelled)
# Check that there's no pending task (add has been cancelled)
for
task
in
asyncio
.
Task
.
all_tasks
(
self
.
loop
):
for
task
in
asyncio
.
Task
.
all_tasks
(
self
.
loop
):
...
@@ -2169,10 +2174,9 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
...
@@ -2169,10 +2174,9 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
def
test_run_coroutine_threadsafe_task_factory_exception
(
self
):
def
test_run_coroutine_threadsafe_task_factory_exception
(
self
):
"""Test coroutine submission from a tread to an event loop
"""Test coroutine submission from a tread to an event loop
when the task factory raise an exception."""
when the task factory raise an exception."""
# Clear the time generator
asyncio
.
ensure_future
(
self
.
add
(
1
,
2
),
loop
=
self
.
loop
)
# Schedule the target
# Schedule the target
future
=
self
.
loop
.
run_in_executor
(
None
,
self
.
target
)
future
=
self
.
loop
.
run_in_executor
(
None
,
lambda
:
self
.
target
(
advance_coro
=
True
))
# Set corrupted task factory
# Set corrupted task factory
self
.
loop
.
set_task_factory
(
lambda
loop
,
coro
:
wrong_name
)
self
.
loop
.
set_task_factory
(
lambda
loop
,
coro
:
wrong_name
)
# Set exception handler
# Set exception handler
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment