diff --git a/locust/clients.py b/locust/clients.py index c4f3d385bc..db47b74ea7 100644 --- a/locust/clients.py +++ b/locust/clients.py @@ -132,7 +132,7 @@ def request(self, method, url, name=None, catch_response=False, context={}, **kw # use stream=True to avoid closing socket and downloading content at the beginning # we'll download content if actually requested a bit later - # + # # a bit of a hack to actually estimate fetching time stream = kwargs.pop("stream", False) diff --git a/locust/test/test_fasthttp.py b/locust/test/test_fasthttp.py index c379083156..aaf9f71720 100644 --- a/locust/test/test_fasthttp.py +++ b/locust/test/test_fasthttp.py @@ -76,8 +76,10 @@ def test_response_times_are_separated_in_request_metadata(self): in request metadata """ kwargs = {} + def on_request(**kw): kwargs.update(kw) + self.environment.events.request.add_listener(on_request) s = self.get_client() @@ -88,7 +90,9 @@ def on_request(**kw): self.assertLess(kwargs["response_fetching_time"], 10) self.assertAlmostEqual( self.runner.stats.get("/streaming/50", method="GET").avg_response_time, - kwargs["response_waiting_time"] + kwargs["response_fetching_time"], delta=0.1) + kwargs["response_waiting_time"] + kwargs["response_fetching_time"], + delta=0.1, + ) self.runner.stats.clear_all() kwargs.clear() @@ -99,7 +103,9 @@ def on_request(**kw): self.assertGreater(kwargs["response_fetching_time"], 250) self.assertAlmostEqual( self.runner.stats.get("/streaming/50", method="GET").avg_response_time, - kwargs["response_waiting_time"] + kwargs["response_fetching_time"], delta=0.1) + kwargs["response_waiting_time"] + kwargs["response_fetching_time"], + delta=0.1, + ) def test_slow_redirect(self): s = self.get_client() diff --git a/locust/test/test_http.py b/locust/test/test_http.py index 47d3e471d0..b473df7bf1 100644 --- a/locust/test/test_http.py +++ b/locust/test/test_http.py @@ -67,8 +67,10 @@ def test_response_times_are_separated_in_request_metadata(self): in request metadata """ kwargs = {} + def on_request(**kw): kwargs.update(kw) + self.environment.events.request.add_listener(on_request) s = self.get_client() @@ -79,7 +81,9 @@ def on_request(**kw): self.assertLess(kwargs["response_fetching_time"], 10) self.assertAlmostEqual( self.runner.stats.get("/streaming/50", method="GET").avg_response_time, - kwargs["response_waiting_time"] + kwargs["response_fetching_time"], delta=0.1) + kwargs["response_waiting_time"] + kwargs["response_fetching_time"], + delta=0.1, + ) self.runner.stats.clear_all() kwargs.clear() @@ -90,8 +94,9 @@ def on_request(**kw): self.assertGreater(kwargs["response_fetching_time"], 250) self.assertAlmostEqual( self.runner.stats.get("/streaming/50", method="GET").avg_response_time, - kwargs["response_waiting_time"] + kwargs["response_fetching_time"], delta=0.1) - + kwargs["response_waiting_time"] + kwargs["response_fetching_time"], + delta=0.1, + ) def test_slow_redirect(self): s = self.get_client()