locustio / locust

Write scalable load tests in plain Python 🚗💨
MIT License
24.51k stars 2.95k forks source link

aborting task in on_start #435

Closed xrmx closed 7 years ago

xrmx commented 8 years ago

I call a function that may fail in TaskSet.on_start

    def on_start(self):
        self.token = self.get_token(user)

I've added a self.interrupt(reschedule=False) call if the function fail but the docstring of the that method says i should not do that from the root taskset.

And in fact i got these errors logged:

[2016-06-21 17:16:29,939] rieux/ERROR/stderr: raise InterruptTaskSet(reschedule)
[2016-06-21 17:16:29,939] rieux/ERROR/stderr: LocustError: A task inside a Locust class' main TaskSet (`WebsiteUser.task_set` of type `UserBehavior`) seems to have called interrupt() or raised an InterruptTaskSet exception. The interrupt() function is used to hand over execution to a parent TaskSet, and should never be called in the main TaskSet which a Locust class' task_set attribute points to.
[2016-06-21 17:16:29,939] rieux/ERROR/stderr: <Greenlet at 0x7f2c67b432d0: start_locust(<class 'http.WebsiteUser'>)> failed with LocustError

How can i avoid to run a task i know would return an error?

heyman commented 7 years ago

What is it that you want to happen when it fails in on_start?

xrmx commented 7 years ago

My memory is a bit foggy on the topic, anyway i think consider the creation of the locust instance as failed but continue with the hatch of the others.

heyman commented 7 years ago

I see. That's not something that is currently supported and unless there's a strong use-case for it, I don't think it's something that will be implemented in Locust.

However, I guess the result in your case was that the failed locust instances stopped, but the ones that didn't failed continued to execute. Which might be sort of equivalent of having some kind of failed state (even though the logs were filled with stacktraces)?

danihodovic commented 4 months ago

Ping in 2024. My use case is that I want the Locust user to abort if authentication fails because all subsequent calls by that user will fail due to auth errors.