From 30f2fa2e804382948ed0cb048ce849ee6d24d13c Mon Sep 17 00:00:00 2001 From: skivis Date: Thu, 3 Oct 2019 21:55:33 +0200 Subject: [PATCH 1/4] Set _cached_content in ContextManager --- locust/contrib/fasthttp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py index f5ee057882..f1ff5c273e 100644 --- a/locust/contrib/fasthttp.py +++ b/locust/contrib/fasthttp.py @@ -316,6 +316,8 @@ class ResponseContextManager(FastResponse): def __init__(self, response): # copy data from response to this object self.__dict__ = response.__dict__ + if isinstance(response, FastResponse): + self._cached_content = response._cached_content def __enter__(self): return self From 7ce89a0083ee62af08d8326d2bf51212cdac1c55 Mon Sep 17 00:00:00 2001 From: skivis Date: Fri, 4 Oct 2019 11:45:59 +0200 Subject: [PATCH 2/4] Use content property instead of _cached_content --- locust/contrib/fasthttp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py index f1ff5c273e..65b7b7100c 100644 --- a/locust/contrib/fasthttp.py +++ b/locust/contrib/fasthttp.py @@ -317,7 +317,7 @@ def __init__(self, response): # copy data from response to this object self.__dict__ = response.__dict__ if isinstance(response, FastResponse): - self._cached_content = response._cached_content + self._cached_content = response.content def __enter__(self): return self From 6d66eafaaac70a897764b3750560539a722ec1a2 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 18 Oct 2019 16:10:09 +0200 Subject: [PATCH 3/4] No need to check type, since it should only be passed FastResponse objects --- locust/contrib/fasthttp.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py index 65b7b7100c..7a0a290be1 100644 --- a/locust/contrib/fasthttp.py +++ b/locust/contrib/fasthttp.py @@ -316,8 +316,7 @@ class ResponseContextManager(FastResponse): def __init__(self, response): # copy data from response to this object self.__dict__ = response.__dict__ - if isinstance(response, FastResponse): - self._cached_content = response.content + self._cached_content = response.content def __enter__(self): return self From dabc1b82623d6981f0b440a0df33393fb91415bb Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Fri, 18 Oct 2019 16:18:00 +0200 Subject: [PATCH 4/4] Improved test (catches bug reported in #1105) --- locust/test/test_fasthttp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/locust/test/test_fasthttp.py b/locust/test/test_fasthttp.py index d90666ff22..dcef48ceaa 100644 --- a/locust/test/test_fasthttp.py +++ b/locust/test/test_fasthttp.py @@ -314,6 +314,7 @@ def test_catch_response(self): with self.locust.client.get("/ultra_fast", catch_response=True) as response: pass self.assertEqual(1, self.num_failures) self.assertEqual(1, self.num_success) + self.assertIn("ultra fast", str(response.content)) with self.locust.client.get("/ultra_fast", catch_response=True) as response: raise ResponseError("Not working")