Skip to content

Commit

Permalink
Fix incorrect first wait time for constant pacing. It incorrectly ass…
Browse files Browse the repository at this point in the history
…umed the first iteration was instantaneous (because it had no way of knowing when the first iteration started)
  • Loading branch information
cyberw committed Oct 19, 2023
1 parent 2700a5d commit 0e10e59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions locust/user/users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from typing import Callable, Dict, List, Optional, final

import time
from gevent import GreenletExit, greenlet
from gevent.pool import Group
from urllib3 import PoolManager
Expand Down Expand Up @@ -119,6 +120,7 @@ def __init__(self, environment):
self._greenlet: greenlet.Greenlet = None
self._group: Group
self._taskset_instance: TaskSet = None
self._cp_last_run = time.time() # used by constant_pacing wait_time

def on_start(self):
"""
Expand Down
15 changes: 6 additions & 9 deletions locust/user/wait_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ def my_task(self):
"""

def wait_time_func(self):
if not hasattr(self, "_cp_last_run"):
self._cp_last_wait_time = wait_time
self._cp_last_run = time()
return wait_time
else:
run_time = time() - self._cp_last_run - self._cp_last_wait_time
self._cp_last_wait_time = max(0, wait_time - run_time)
self._cp_last_run = time()
return self._cp_last_wait_time
if not hasattr(self, "_cp_last_wait_time"):
self._cp_last_wait_time = 0
run_time = time() - self._cp_last_run - self._cp_last_wait_time
self._cp_last_wait_time = max(0, wait_time - run_time)
self._cp_last_run = time()
return self._cp_last_wait_time

return wait_time_func

Expand Down

0 comments on commit 0e10e59

Please sign in to comment.