Skip to content

Commit

Permalink
Remove setup and teardown hooks from Locust/Taskset (they will be rep…
Browse files Browse the repository at this point in the history
…laced by events, since that makes much more sense)
  • Loading branch information
heyman committed Apr 4, 2020
1 parent 2a0a6ef commit 7d5f6fa
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 59 deletions.
50 changes: 0 additions & 50 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from time import time

import gevent
import gevent.lock

from gevent import GreenletExit, monkey

# The monkey patching must run before requests is imported, or else
Expand Down Expand Up @@ -207,10 +205,6 @@ class ForumPage(TaskSet):
instantiated. Useful for nested TaskSet classes.
"""

_setup_has_run = False # Internal state to see if we have already run
_teardown_is_set = False # Internal state to see if we have already run
_lock = gevent.lock.Semaphore() # Lock to make sure setup is only run once

def __init__(self, parent):
# check if deprecated wait API is used
deprecation.check_for_deprecated_wait_api(self)
Expand All @@ -235,26 +229,6 @@ def __init__(self, parent):
if not self.wait_function:
self.wait_function = self.locust.wait_function

with self._lock:
if hasattr(self, "setup") and self._setup_has_run is False:
self._set_setup_flag()
try:
self.setup()
except Exception as e:
self.locust.environment.events.locust_error.fire(locust_instance=self, exception=e, tb=sys.exc_info()[2])
logger.error("%s\n%s", e, traceback.format_exc())
if hasattr(self, "teardown") and self._teardown_is_set is False:
self._set_teardown_flag()
self.environment.events.quitting.add_listener(self.teardown)

@classmethod
def _set_setup_flag(cls):
cls._setup_has_run = True

@classmethod
def _set_teardown_flag(cls):
cls._teardown_is_set = True

def on_start(self):
"""
Hook for end-user scripts for running code when a Locust user starts running
Expand Down Expand Up @@ -538,38 +512,14 @@ class ForumPage(TaskSet):

client = NoClientWarningRaiser()
_catch_exceptions = True
_setup_has_run = False # Internal state to see if we have already run
_teardown_is_set = False # Internal state to see if we have already run
_lock = gevent.lock.Semaphore() # Lock to make sure setup is only run once
_state = None
_greenlet = None

def __init__(self, environment):
super(Locust, self).__init__()
# check if deprecated wait API is used
deprecation.check_for_deprecated_wait_api(self)

self.environment = environment

with self._lock:
if hasattr(self, "setup") and self._setup_has_run is False:
self._set_setup_flag()
try:
self.setup()
except Exception as e:
self.environment.events.locust_error.fire(locust_instance=self, exception=e, tb=sys.exc_info()[2])
logger.error("%s\n%s", e, traceback.format_exc())
if hasattr(self, "teardown") and self._teardown_is_set is False:
self._set_teardown_flag()
self.environment.events.quitting.add_listener(self.teardown)

@classmethod
def _set_setup_flag(cls):
cls._setup_has_run = True

@classmethod
def _set_teardown_flag(cls):
cls._teardown_is_set = True

def on_start(self):
"""
Expand Down
9 changes: 0 additions & 9 deletions locust/test/test_locust_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,6 @@ class MyLocust(Locust):


class TestLocustClass(LocustTestCase):
def test_setup_method(self):
class User(Locust):
setup_run_count = 0
def setup(self):
User.setup_run_count += 1
User(self.environment)
User(self.environment)
self.assertEqual(1, User.setup_run_count)

def test_locust_on_start(self):
class MyLocust(Locust):
t1_executed = False
Expand Down

0 comments on commit 7d5f6fa

Please sign in to comment.