Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace time.time() with time.monotonic() #1492

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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