Skip to content

Commit

Permalink
Replace time.time() with time.monotonic() in
Browse files Browse the repository at this point in the history
  • Loading branch information
max-rocket-internet committed Jul 23, 2020
1 parent b18cf1e commit 712203b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions locust/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions locust/test/test_wait_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down

0 comments on commit 712203b

Please sign in to comment.