Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fail setup in Locust?

Tags:

python

locust

I'm doing a verification in my Locust setup and if that fails, I would like locust to exit immediately.

To do that, I'm raising an exception, but locust continues with the tests until time limit is reached.

I'd like for it to not even start the tests if setup fails. Is there a way to do that?

Locust code

class MyLocust(Locust):
    task_set = MyTaskSet

    def setup(self):
        if True:
            raise ValueError('Setup failed')

stdout / stderr:

locust -f MyTest.py --no-web -c 10 -r 10 -t 5s

INFO/locust.main: Run time limit set to 5 seconds
INFO/locust.main: Starting Locust 0.11.0
INFO/locust.runners: Hatching and swarming 10 clients at the rate 10 clients/s...
    Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                              0     0(0.00%)                                       0.00

ERROR/stderr: Traceback (most recent call last):
ERROR/stderr: 
ERROR/stderr: File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
ERROR/stderr: 
ERROR/stderr: File "/venv_37_1/lib/python3.7/site-packages/locust/runners.py", line 114, in start_locust
    locust().run(runner=self)
ERROR/stderr: 
ERROR/stderr: File "/venv_37_1/lib/python3.7/site-packages/locust/core.py", line 192, in __init__
    super(HttpLocust, self).__init__()
ERROR/stderr: 
ERROR/stderr: File "/venv_37_1/lib/python3.7/site-packages/locust/core.py", line 143, in __init__
    self.setup()
ERROR/stderr: 
ERROR/stderr: File "/MyTest.py", line 220, in setup
    raise ValueError('Setup failed')
ERROR/stderr: 
ERROR/stderr: ValueError: Setup failed
ERROR/stderr: 
ERROR/stderr: 2019-09-25T21:43:39Z
ERROR/stderr: 
ERROR/stderr: <Greenlet at 0x12c8c2950: start_locust(<class 'MyTest.LoadTest'>)> failed with ValueError
INFO/locust.runners: All locusts hatched: LoadTest: 10
    Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                              0     0(0.00%)                                       0.00

    Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                              0     0(0.00%)                                       0.00

INFO/locust.main: Time limit reached. Stopping Locust.
INFO/locust.main: Shutting down (exit code 0), bye.
INFO/locust.main: Cleaning up runner...
INFO/locust.main: Running teardowns...

As you can see from ^ only exits when time limit is reached, even though setup failed.

like image 670
Joao Coelho Avatar asked Sep 25 '19 21:09

Joao Coelho


1 Answers

For me - helps this thing. Just one problem - locust exits with code 0, like "successful"

import greenlet


class MyLocust(Locust):
    task_set = MyTaskSet

    def setup(self):
        if True:
            raise greenlet.error('Setup failed')
like image 145
Денис Поздняков Avatar answered Nov 13 '22 15:11

Денис Поздняков