Skip to content

Commit a0c7694

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 a0c7694

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-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

+20
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ 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_failure(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("some error")
83+
84+
stats = self.runner.stats.get("/streaming/30", "GET")
85+
self.assertEqual(1, stats.num_requests)
86+
self.assertEqual(1, stats.num_failures)
87+
88+
self.assertGreaterEqual(stats.avg_response_time, 0)
89+
self.assertLess(stats.avg_response_time, 250)
90+
91+
# download the content of the streaming response (so we don't get an ugly exception in the log)
92+
_ = r.content
93+
7494
def test_slow_redirect(self):
7595
s = self.get_client()
7696
url = "/redirect?url=/redirect&delay=0.5"

0 commit comments

Comments
 (0)