Skip to content

Commit

Permalink
Assert that every user actually triggered on_stop, even in special ca…
Browse files Browse the repository at this point in the history
…ses.
  • Loading branch information
cyberw committed Sep 15, 2020
1 parent f6db44e commit 2c1cdcf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,15 @@ def test_runner_reference_on_environment(self):
def test_users_can_call_runner_quit_without_deadlocking(self):
class BaseUser(User):
wait_time = constant(0)
stop_triggered = False

@task
def trigger(self):
self.environment.runner.quit()

def on_stop(self):
BaseUser.stop_triggered = True

runner = Environment(user_classes=[BaseUser]).create_local_runner()
runner.spawn_users(1, 1, wait=False)
timeout = gevent.Timeout(0.5)
Expand All @@ -380,20 +384,24 @@ def trigger(self):
finally:
timeout.cancel()

def test_runner_quit_does_not_get_blocked_by_slow_on_stop(self):
self.assertTrue(BaseUser.stop_triggered)

def test_runner_quit_can_run_on_stop_for_multiple_users_concurrently(self):
class BaseUser(User):
wait_time = constant(0)
stop_count = 0

@task
def trigger(self):
pass

def on_stop(self):
gevent.sleep(0.2)
gevent.sleep(0.1)
BaseUser.stop_count += 1

runner = Environment(user_classes=[BaseUser]).create_local_runner()
runner.spawn_users(10, 10, wait=False)
timeout = gevent.Timeout(0.4)
timeout = gevent.Timeout(0.3)
timeout.start()
try:
runner.quit()
Expand All @@ -402,6 +410,8 @@ def on_stop(self):
finally:
timeout.cancel()

self.assertEqual(10, BaseUser.stop_count) # verify that all users executed on_stop

def test_stop_users_with_spawn_rate(self):
class MyUser(User):
wait_time = constant(1)
Expand Down

0 comments on commit 2c1cdcf

Please sign in to comment.