You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@events.quitting.add_listener
def _(environment, **kw):
if environment.stats.total.fail_ratio > 0.01:
logging.error("Test failed due to failure ratio > 1%")
environment.process_exit_code = 1
elif environment.stats.total.avg_response_time > 200:
logging.error("Test failed due to average response time ratio > 200 ms")
environment.process_exit_code = 1
elif environment.stats.total.get_response_time_percentile(0.95) > 800:
logging.error("Test failed due to 95th percentile response time > 800 ms")
environment.process_exit_code = 1
else:
environment.process_exit_code = 0
The above code, placed in my user class file, did not print the corresponding log, and the stress testing interface also reported an error. The code still did not work
I have updated to 2.27.0, but it still hasn't been triggered
locust -f locustfile.py --users 10 --spawn-rate 10 --host=https://www.asdashdkjashd.com --run-time 60s
from locust import HttpUser, task, events, between
import logging
class MyUser(HttpUser):
wait_time = between(1, 5)
@task
def my_task(self):
with self.client.get("/") as response:
pass
@events.quitting.add_listener
def _(environment, **kw):
if environment.stats.total.fail_ratio > 0.01:
logging.error("Test failed due to failure ratio > 1%")
environment.process_exit_code = 1
elif environment.stats.total.avg_response_time > 200:
logging.error("Test failed due to average response time ratio > 200 ms")
environment.process_exit_code = 1
elif environment.stats.total.get_response_time_percentile(0.95) > 80:
logging.error("Test failed due to 95th percentile response time > 800 ms")
environment.process_exit_code = 1
else:
environment.process_exit_code = 0
------------------ 原始邮件 ------------------
发件人: "locustio/locust" ***@***.***>;
发送时间: 2024年5月18日(星期六) 晚上10:23
***@***.***>;
***@***.******@***.***>;
主题: Re: [locustio/locust] The exit code for controlling the locust process has a bug (Issue #2716)
Please use latest version
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
Prerequisites
Description
import logging
from locust import events
@events.quitting.add_listener
def _(environment, **kw):
if environment.stats.total.fail_ratio > 0.01:
logging.error("Test failed due to failure ratio > 1%")
environment.process_exit_code = 1
elif environment.stats.total.avg_response_time > 200:
logging.error("Test failed due to average response time ratio > 200 ms")
environment.process_exit_code = 1
elif environment.stats.total.get_response_time_percentile(0.95) > 800:
logging.error("Test failed due to 95th percentile response time > 800 ms")
environment.process_exit_code = 1
else:
environment.process_exit_code = 0
The above code, placed in my user class file, did not print the corresponding log, and the stress testing interface also reported an error. The code still did not work
Command line
locust -f locustfile.py --users 10 --spawn-rate 10 --host=https://********com --run-time 60s
Locustfile contents
nothing
Python version
3.9.6
Locust version
2.20.0
Operating system
mac os
The text was updated successfully, but these errors were encountered: