File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -578,7 +578,10 @@ class ResponseContextManager(FastResponse):
578
578
def __init__ (self , response , environment , request_meta ):
579
579
# copy data from response to this object
580
580
self .__dict__ = response .__dict__
581
- self ._cached_content = response .content
581
+ try :
582
+ self ._cached_content = response ._cached_content
583
+ except AttributeError :
584
+ pass
582
585
# store reference to locust Environment
583
586
self ._environment = environment
584
587
self .request_meta = request_meta
Original file line number Diff line number Diff line change @@ -71,6 +71,28 @@ def test_streaming_response(self):
71
71
# download the content of the streaming response (so we don't get an ugly exception in the log)
72
72
_ = r .content
73
73
74
+ def test_streaming_response_catch_response (self ):
75
+ """
76
+ Test a request to an endpoint that returns a streaming response, and uses catch_response
77
+ """
78
+ s = self .get_client ()
79
+
80
+ with s .get ("/streaming/30" , stream = True , catch_response = True ) as r :
81
+ # typical usage of r when stream=True is to read the stream as desired,
82
+ # with the possibility to "fail fast" when some things are read early on
83
+ response_content = str (r .stream .read ())
84
+ r .failure ("some error" )
85
+
86
+ self .assertRegex (response_content , "streaming response" )
87
+
88
+ stats = self .runner .stats .get ("/streaming/30" , "GET" )
89
+ self .assertEqual (1 , stats .num_requests )
90
+ self .assertEqual (1 , stats .num_failures )
91
+
92
+ # verify that response time does NOT include whole download time, when using stream=True
93
+ self .assertGreaterEqual (stats .avg_response_time , 0 )
94
+ self .assertLess (stats .avg_response_time , 250 )
95
+
74
96
def test_slow_redirect (self ):
75
97
s = self .get_client ()
76
98
url = "/redirect?url=/redirect&delay=0.5"
You can’t perform that action at this time.
0 commit comments