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

Allow self.interrupt() inside on_start #95

Closed
joefreeman opened this issue Sep 13, 2013 · 2 comments
Closed

Allow self.interrupt() inside on_start #95

joefreeman opened this issue Sep 13, 2013 · 2 comments

Comments

@joefreeman
Copy link

I think it would make sense to allow interrupt()-ing from inside the on_start method.

This would allow a TaskSet for, say, updating 'widgets' where the on_start gets a list of widgets, then tasks within the TaskSet perform various updates to the widgets. However, in the case where there are no widgets yet, the TaskSet would be interrupt()-ed.

I was hoping to be able to do something like this:

class WidgetTasks(locust.TaskSet):

  def on_start(self):
    r = self.client.get("/widgets")
    self.widgets = r.json["widgets"]
    if not self.widgets:
      # there are no widgets to update, so jump out of this TaskSet
      self.interrupt()

  @locust.task
  def update_widget_name(self):
    widget = random.choice(self.widgets)
    self.client.put(
      "/widgets/{0}/name".format(widget["id"]),
      data="New Name")

  # etc...

class UserTasks(locust.TaskSet):

  tasks = {WidgetTasks: 1}

  @locust.task
  def create_widget(self):
    self.client.post("/widgets")

  # etc...

I hope this make sense?

I think it would just be a case of lifting this except block out into another try block that wrapped the call to on_start and the while loop? I'd submit a pull request myself, but I haven't been able to get the unit tests to run.

@heyman heyman closed this as completed in 8b7b613 Sep 13, 2013
@heyman
Copy link
Member

heyman commented Sep 13, 2013

I agree. Pushed a fix!

What problem are you having with unit tests?

@joefreeman
Copy link
Author

Awesome, thank you!

I initially wasn't sure how to run the tests, and then didn't spend enough time installing the dependencies. But python -m unittest discover seems to work now that I've installed python-msgpack and mock.

I do still occasionally get this failure though:

======================================================================
FAIL: test_moving_average_100 (locust.test.test_average.MovingAverageTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/joe/Projects/Public/locust/locust/test/test_average.py", line 58, in test_moving_average_100
    self._assertion(taskset, deviation, max_deviation, percentage)
  File "/Users/joe/Projects/Public/locust/locust/test/test_average.py", line 45, in _assertion
    self.assertTrue(deviation < max_deviation, msg="Deviation not within %s%% of wanted average" % percentage)
AssertionError: Deviation not within 5.0% of wanted average

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants