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
df75d5b4
Commit
df75d5b4
authored
Dec 11, 2014
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asyncio, tulip issue 202: Add unit test of pause/resume writing for proactor
socket transport
parent
049882e5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
4 deletions
+82
-4
Lib/asyncio/proactor_events.py
Lib/asyncio/proactor_events.py
+0
-4
Lib/test/test_asyncio/test_proactor_events.py
Lib/test/test_asyncio/test_proactor_events.py
+82
-0
No files found.
Lib/asyncio/proactor_events.py
View file @
df75d5b4
...
...
@@ -230,10 +230,6 @@ class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport,
assert
self
.
_buffer
is
None
# Pass a copy, except if it's already immutable.
self
.
_loop_writing
(
data
=
bytes
(
data
))
# XXX Should we pause the protocol at this point
# if len(data) > self._high_water? (That would
# require keeping track of the number of bytes passed
# to a send() that hasn't finished yet.)
elif
not
self
.
_buffer
:
# WRITING -> BACKED UP
# Make a mutable copy which we can extend.
self
.
_buffer
=
bytearray
(
data
)
...
...
Lib/test/test_asyncio/test_proactor_events.py
View file @
df75d5b4
...
...
@@ -343,6 +343,88 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr
.
close
()
def
pause_writing_transport
(
self
,
high
):
tr
=
_ProactorSocketTransport
(
self
.
loop
,
self
.
sock
,
self
.
protocol
)
self
.
addCleanup
(
tr
.
close
)
tr
.
set_write_buffer_limits
(
high
=
high
)
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
0
)
self
.
assertFalse
(
self
.
protocol
.
pause_writing
.
called
)
self
.
assertFalse
(
self
.
protocol
.
resume_writing
.
called
)
return
tr
def
test_pause_resume_writing
(
self
):
tr
=
self
.
pause_writing_transport
(
high
=
4
)
# write a large chunk, must pause writing
fut
=
asyncio
.
Future
(
loop
=
self
.
loop
)
self
.
loop
.
_proactor
.
send
.
return_value
=
fut
tr
.
write
(
b'large data'
)
self
.
loop
.
_run_once
()
self
.
assertTrue
(
self
.
protocol
.
pause_writing
.
called
)
# flush the buffer
fut
.
set_result
(
None
)
self
.
loop
.
_run_once
()
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
0
)
self
.
assertTrue
(
self
.
protocol
.
resume_writing
.
called
)
def
test_pause_writing_2write
(
self
):
tr
=
self
.
pause_writing_transport
(
high
=
4
)
# first short write, the buffer is not full (3 <= 4)
fut1
=
asyncio
.
Future
(
loop
=
self
.
loop
)
self
.
loop
.
_proactor
.
send
.
return_value
=
fut1
tr
.
write
(
b'123'
)
self
.
loop
.
_run_once
()
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
3
)
self
.
assertFalse
(
self
.
protocol
.
pause_writing
.
called
)
# fill the buffer, must pause writing (6 > 4)
tr
.
write
(
b'abc'
)
self
.
loop
.
_run_once
()
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
6
)
self
.
assertTrue
(
self
.
protocol
.
pause_writing
.
called
)
def
test_pause_writing_3write
(
self
):
tr
=
self
.
pause_writing_transport
(
high
=
4
)
# first short write, the buffer is not full (1 <= 4)
fut
=
asyncio
.
Future
(
loop
=
self
.
loop
)
self
.
loop
.
_proactor
.
send
.
return_value
=
fut
tr
.
write
(
b'1'
)
self
.
loop
.
_run_once
()
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
1
)
self
.
assertFalse
(
self
.
protocol
.
pause_writing
.
called
)
# second short write, the buffer is not full (3 <= 4)
tr
.
write
(
b'23'
)
self
.
loop
.
_run_once
()
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
3
)
self
.
assertFalse
(
self
.
protocol
.
pause_writing
.
called
)
# fill the buffer, must pause writing (6 > 4)
tr
.
write
(
b'abc'
)
self
.
loop
.
_run_once
()
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
6
)
self
.
assertTrue
(
self
.
protocol
.
pause_writing
.
called
)
def
test_dont_pause_writing
(
self
):
tr
=
self
.
pause_writing_transport
(
high
=
4
)
# write a large chunk which completes immedialty,
# it should not pause writing
fut
=
asyncio
.
Future
(
loop
=
self
.
loop
)
fut
.
set_result
(
None
)
self
.
loop
.
_proactor
.
send
.
return_value
=
fut
tr
.
write
(
b'very large data'
)
self
.
loop
.
_run_once
()
self
.
assertEqual
(
tr
.
get_write_buffer_size
(),
0
)
self
.
assertFalse
(
self
.
protocol
.
pause_writing
.
called
)
class
BaseProactorEventLoopTests
(
test_utils
.
TestCase
):
def
setUp
(
self
):
...
...
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