diff --git a/locust/test/test_runners.py b/locust/test/test_runners.py index f58c006f44..b28c43acc4 100644 --- a/locust/test/test_runners.py +++ b/locust/test/test_runners.py @@ -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) @@ -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() @@ -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)