[英]How to fail setup in Locust?
I'm doing a verification in my Locust setup and if that fails, I would like locust to exit immediately.我正在我的 Locust 设置中进行验证,如果失败,我希望 locust 立即退出。
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.从 ^ 中可以看出,即使
setup
失败,也只有在达到时间限制时才会退出。
For me - helps this thing.对我来说 - 帮助这件事。 Just one problem - locust exits with code 0, like "successful"
只有一个问题 - 蝗虫以代码 0 退出,例如“成功”
import greenlet
class MyLocust(Locust):
task_set = MyTaskSet
def setup(self):
if True:
raise greenlet.error('Setup failed')
If you want stop single locust,use below code.如果你想阻止单个蝗虫,请使用下面的代码。 locust.exceptions will help for stop single locust operation.
locust.exceptions 将有助于停止单个蝗虫操作。
from locust.exception import StopLocust
class MyLocust(Locust):
task_set = MyTaskSet
def setup(self):
if True:
raise StopLocust()
If you want stop all locust,use below code.如果你想阻止所有的蝗虫,请使用下面的代码。
from locust.main import runners
class MyLocust(Locust):
task_set = MyTaskSet
def setup(self):
if True:
raise runners.locust_runner.quit()
You could always use quit()
to quit Locust all together.您总是可以使用
quit()
一起退出 Locust。 Another option would be to use raise StopLocust()
:另一种选择是使用
raise StopLocust()
:
class MyLocust(Locust):
task_set = MyTaskSet
def setup(self):
if True:
raise StopLocust()
Also, check this out Stopping a locust另外,看看这个阻止蝗虫
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.