Skip to content

Commit

Permalink
Do not call blocking content property and lazily load response on fir…
Browse files Browse the repository at this point in the history
…st access

This reverts commit 7ce89a0 and improves it
  • Loading branch information
neiser committed Mar 19, 2024
1 parent c69316d commit ebe49a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ class ResponseContextManager(FastResponse):
def __init__(self, response, environment, request_meta):
# copy data from response to this object
self.__dict__ = response.__dict__
self._cached_content = response.content
try:
self._cached_content = response._cached_content
except AttributeError:
pass
# store reference to locust Environment
self._environment = environment
self.request_meta = request_meta
Expand Down
16 changes: 16 additions & 0 deletions locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def test_streaming_response(self):
# download the content of the streaming response (so we don't get an ugly exception in the log)
_ = r.content

def test_streaming_response_catch_exception(self):
"""
Test a request to an endpoint that returns a streaming response, and uses catch_response
"""
s = self.get_client()

# verify that response time does NOT include whole download time, when using stream=True
with s.get("/streaming/30", stream=True, catch_response=True) as r:
r.failure("nope")

self.assertGreaterEqual(self.runner.stats.get("/streaming/30", method="GET").avg_response_time, 0)
self.assertLess(self.runner.stats.get("/streaming/30", method="GET").avg_response_time, 250)

# download the content of the streaming response (so we don't get an ugly exception in the log)
_ = r.content

def test_slow_redirect(self):
s = self.get_client()
url = "/redirect?url=/redirect&delay=0.5"
Expand Down

0 comments on commit ebe49a0

Please sign in to comment.