@@ -718,6 +718,66 @@ def socket_handler(listener):
718718
719719 self .tear_down ()
720720
721+ def test_read_delayed (self ):
722+ self .set_up ()
723+
724+ recv_event = threading .Event ()
725+ wait_event = threading .Event ()
726+
727+ def socket_handler (listener ):
728+ sock = listener .accept ()[0 ]
729+
730+ # We get two messages for the connection open and then a HEADERS
731+ # frame.
732+ receive_preamble (sock )
733+ sock .recv (65535 )
734+
735+ # Now, send the headers for the response. This response has a body.
736+ f = build_headers_frame ([(':status' , '200' )])
737+ f .stream_id = 1
738+ sock .send (f .serialize ())
739+
740+ # Send the first two chunks.
741+ f = DataFrame (1 )
742+ f .data = b'hello'
743+ sock .sendall (f .serialize ())
744+ f = DataFrame (1 )
745+ f .data = b'there'
746+ sock .sendall (f .serialize ())
747+
748+ # Now, delay a bit. We want to wait a half a second before we send
749+ # the next frame.
750+ wait_event .wait (5 )
751+ time .sleep (0.5 )
752+ f = DataFrame (1 )
753+ f .data = b'world'
754+ f .flags .add ('END_STREAM' )
755+ sock .sendall (f .serialize ())
756+
757+ # Wait for the message from the main thread.
758+ recv_event .set ()
759+ sock .close ()
760+
761+ self ._start_server (socket_handler )
762+ conn = self .get_connection ()
763+ conn .request ('GET' , '/' )
764+ resp = conn .get_response ()
765+
766+ # Confirm the status code.
767+ assert resp .status == 200
768+
769+ first_chunk = resp .read (10 )
770+ wait_event .set ()
771+ second_chunk = resp .read (5 )
772+
773+ assert first_chunk == b'hellothere'
774+ assert second_chunk == b'world'
775+
776+ # Awesome, we're done now.
777+ recv_event .wait (5 )
778+
779+ self .tear_down ()
780+
721781
722782class TestRequestsAdapter (SocketLevelTest ):
723783 # This uses HTTP/2.
0 commit comments