Skip to content

Commit ebe49a0

Browse files
committed
Do not call blocking content property and lazily load response on first access
This reverts commit 7ce89a0 and improves it
1 parent c69316d commit ebe49a0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: locust/contrib/fasthttp.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,10 @@ class ResponseContextManager(FastResponse):
578578
def __init__(self, response, environment, request_meta):
579579
# copy data from response to this object
580580
self.__dict__ = response.__dict__
581-
self._cached_content = response.content
581+
try:
582+
self._cached_content = response._cached_content
583+
except AttributeError:
584+
pass
582585
# store reference to locust Environment
583586
self._environment = environment
584587
self.request_meta = request_meta

Diff for: locust/test/test_fasthttp.py

+16
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ def test_streaming_response(self):
7171
# download the content of the streaming response (so we don't get an ugly exception in the log)
7272
_ = r.content
7373

74+
def test_streaming_response_catch_exception(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+
# verify that response time does NOT include whole download time, when using stream=True
81+
with s.get("/streaming/30", stream=True, catch_response=True) as r:
82+
r.failure("nope")
83+
84+
self.assertGreaterEqual(self.runner.stats.get("/streaming/30", method="GET").avg_response_time, 0)
85+
self.assertLess(self.runner.stats.get("/streaming/30", method="GET").avg_response_time, 250)
86+
87+
# download the content of the streaming response (so we don't get an ugly exception in the log)
88+
_ = r.content
89+
7490
def test_slow_redirect(self):
7591
s = self.get_client()
7692
url = "/redirect?url=/redirect&delay=0.5"

0 commit comments

Comments
 (0)