From 712203b0b59ed9f3dbacf98f737818671f244fec Mon Sep 17 00:00:00 2001 From: Max Williams Date: Thu, 23 Jul 2020 17:29:42 +0200 Subject: [PATCH] Replace time.time() with time.monotonic() in --- locust/clients.py | 4 ++-- locust/test/test_wait_time.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/locust/clients.py b/locust/clients.py index f9390e73fd..2272d83a2d 100644 --- a/locust/clients.py +++ b/locust/clients.py @@ -109,12 +109,12 @@ def request(self, method, url, name=None, catch_response=False, **kwargs): # set up pre_request hook for attaching meta data to the request object request_meta["method"] = method - request_meta["start_time"] = time.time() + request_meta["start_time"] = time.monotonic() response = self._send_request_safe_mode(method, url, **kwargs) # record the consumed time - request_meta["response_time"] = (time.time() - request_meta["start_time"]) * 1000 + request_meta["response_time"] = (time.monotonic() - request_meta["start_time"]) * 1000 request_meta["name"] = name or (response.history and response.history[0] or response).request.path_url diff --git a/locust/test/test_wait_time.py b/locust/test/test_wait_time.py index 84a6fc6b31..07cf0886f5 100644 --- a/locust/test/test_wait_time.py +++ b/locust/test/test_wait_time.py @@ -47,9 +47,9 @@ class TaskSet1(TaskSet): self.assertEqual(0, MyUser(self.environment).wait_time()) self.assertEqual(0, TaskSet1(MyUser(self.environment)).wait_time()) taskset = TaskSet1(MyUser(self.environment)) - start_time = time.time() + start_time = time.monotonic() taskset.wait() - self.assertLess(time.time() - start_time, 0.002) + self.assertLess(time.monotonic() - start_time, 0.002) def test_constant_pacing(self): class MyUser(User): @@ -60,12 +60,12 @@ class TS(TaskSet): ts2 = TS(MyUser(self.environment)) - previous_time = time.time() + previous_time = time.monotonic() for i in range(7): ts.wait() - since_last_run = time.time() - previous_time + since_last_run = time.monotonic() - previous_time self.assertLess(abs(0.1 - since_last_run), 0.02) - previous_time = time.time() + previous_time = time.monotonic() time.sleep(random.random() * 0.1) _ = ts2.wait_time() _ = ts2.wait_time()