This repository was archived by the owner on Jan 13, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,9 @@ def readline(self):
150150 Read up to a newline from the network and returns it. The implicit
151151 maximum line length is the buffer size of the buffered socket.
152152
153+ Note that, unlike recv, this method absolutely *does* block until it
154+ can read the line.
155+
153156 :returns: A ``memoryview`` object containing the appropriate number of
154157 bytes. The data *must* be copied out by the caller before the next
155158 call to this function.
Original file line number Diff line number Diff line change 55
66Test the BufferedSocket implementation in hyper.
77"""
8+ import pytest
9+
810import hyper .http20 .bufsocket
911from hyper .http20 .bufsocket import BufferedSocket
12+ from hyper .http20 .exceptions import ConnectionResetError , LineTooLongError
1013
1114# Patch the select method in bufsocket to make sure that it always returns
1215# the dummy socket as readable.
@@ -181,6 +184,29 @@ def test_readline_both(self, monkeypatch):
181184 assert b .readline ().tobytes () == two
182185 assert b .readline ().tobytes () == three
183186
187+ def test_socket_error_on_readline (self , monkeypatch ):
188+ monkeypatch .setattr (
189+ hyper .http20 .bufsocket .select , 'select' , dummy_select
190+ )
191+ s = DummySocket ()
192+ b = BufferedSocket (s )
193+
194+ with pytest .raises (ConnectionResetError ):
195+ b .readline ()
196+
197+ def test_socket_readline_too_long (self , monkeypatch ):
198+ monkeypatch .setattr (
199+ hyper .http20 .bufsocket .select , 'select' , dummy_select
200+ )
201+ s = DummySocket ()
202+ b = BufferedSocket (s )
203+
204+ b ._buffer_view [0 :b ._buffer_size ] = b'0' * b ._buffer_size
205+ b ._bytes_in_buffer = b ._buffer_size
206+
207+ with pytest .raises (LineTooLongError ):
208+ b .readline ()
209+
184210
185211class DummySocket (object ):
186212 def __init__ (self ):
You can’t perform that action at this time.
0 commit comments