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

Fix and add test for when locusts fail to exit at end of iteration during stop timeout. #1127

Merged
merged 4 commits into from
Oct 31, 2019
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
9 changes: 6 additions & 3 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,18 @@ def run(self, *args, **kwargs):

while (True):
try:
if self.locust._state == LOCUST_STATE_STOPPING:
raise GreenletExit()

if not self._task_queue:
self.schedule_task(self.get_next_task())

try:
if self.locust._state == LOCUST_STATE_STOPPING:
raise GreenletExit()
self.execute_next_task()
if self.locust._state == LOCUST_STATE_STOPPING:
raise GreenletExit()
except RescheduleTaskImmediately:
if self.locust._state == LOCUST_STATE_STOPPING:
raise GreenletExit()
pass
except RescheduleTask:
self.wait()
Expand Down
42 changes: 40 additions & 2 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ def my_task(self):

class MyTestLocust(Locust):
task_set = MyTaskSet
min_wait = 0
max_wait = 0

options = mocked_options()
runner = LocalLocustRunner([MyTestLocust], options)
Expand All @@ -517,13 +519,49 @@ class MyTestLocust(Locust):
runner.quit()
self.assertEqual("second", MyTaskSet.state)

options.stop_timeout = short_time * 2 # allow task iteration to complete, with some margin
options.stop_timeout = short_time * 3 # allow task iteration to complete, with some margin
runner = LocalLocustRunner([MyTestLocust], options)
runner.start_hatching(1, 1)
gevent.sleep(short_time)
runner.quit()
timeout = gevent.Timeout(short_time * 2)
timeout.start()
try:
runner.quit()
runner.greenlet.join()
except gevent.Timeout:
self.fail("Got Timeout exception. Some locusts must have kept runnining after iteration finish")
finally:
timeout.cancel()
self.assertEqual("third", MyTaskSet.state)

def test_stop_timeout_during_on_start(self):
short_time = 0.05
class MyTaskSet(TaskSet):
finished_on_start = False
my_task_run = False
def on_start(self):
gevent.sleep(short_time)
MyTaskSet.finished_on_start = True

@task
def my_task(self):
MyTaskSet.my_task_run = True

class MyTestLocust(Locust):
task_set = MyTaskSet
min_wait = 0
max_wait = 0

options = mocked_options()
options.stop_timeout = short_time
runner = LocalLocustRunner([MyTestLocust], options)
runner.start_hatching(1, 1)
gevent.sleep(short_time / 2)
runner.quit()

self.assertTrue(MyTaskSet.finished_on_start)
self.assertFalse(MyTaskSet.my_task_run)

def test_stop_timeout_exit_during_wait(self):
short_time = 0.05
class MyTaskSet(TaskSet):
Expand Down