Skip to content

Commit

Permalink
Tweak cpu warning test for reliability with new solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberw committed Dec 21, 2024
1 parent 55b274a commit b5ac53d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ def t(self):

def test_cpu_warning(self):
_monitor_interval = runners.CPU_MONITOR_INTERVAL
runners.CPU_MONITOR_INTERVAL = 2.0
runners.CPU_MONITOR_INTERVAL = 0.1
try:

class CpuUser(User):
wait_time = constant(0.001)

@task
def cpu_task(self):
for i in range(1000000):
_ = 3 / 2
for i in range(10):
for j in range(1000000):
_ = 3 / 2
time.sleep(0.0001) # let other greenlets run, like the cpu monitor

environment = Environment(user_classes=[CpuUser])
environment._cpu_warning_event_triggered = False
Expand All @@ -181,6 +181,7 @@ def cpu_warning(environment, cpu_usage, **kwargs):

environment.events.cpu_warning.add_listener(cpu_warning)
runner = LocalRunner(environment)
time.sleep(0.2) # let first checks run
self.assertFalse(runner.cpu_warning_emitted)
runner.spawn_users({CpuUser.__name__: 1}, wait=False)
sleep(2.5)
Expand Down

0 comments on commit b5ac53d

Please sign in to comment.