【发布时间】:2018-03-22 22:40:27
【问题描述】:
我正在尝试了解蝗虫测试中的流程。我已经设置了这个非常简单的任务集和用户:
from locust import TaskSet, HttpLocust, task
class BlazeDemoTaskSet(TaskSet):
def setup(self):
print("hello from taskset setup")
def teardown(self):
print("hello from taskset teardown")
def on_start(self):
print("hello from taskset on_start")
def on_stop(self):
print("hello from taskset on_stop")
@task
def reserve_task(self):
post_response = self.client.post(
url="/reserve.php",
params={"toPort":"Buenos Aries", "fromPort":"Paris"})
class BlazeDemoUser(HttpLocust):
task_set = BlazeDemoTaskSet
min_wait = 500
max_wait = 1500
host = "http://www.blazedemo.com"
def setup(self):
print("hello from httplocust setup")
def teardown(self):
print("hello from httplocust teardown")
我运行它:
locust -f tests/blazedemo.py --no-web -c 1 -r 1 -n 2
我没有看到正在执行的 HttpLocust setup 或 teardown 方法,也没有看到正在执行的 TaskSet setup、on_stop 或 teardown 方法。唯一可以运行的方法是 on_start 和 reserve_task
According to the docs 所有这些方法都应该运行。每次运行都设置和拆卸一次,并且为每个启动的用户设置 on_start 和 on_stop。
这是 Locust 的全部输出:
[2018-03-22 18:26:50,698] C02PV7NSG8WP/INFO/locust.main: Starting Locust 0.8.1
[2018-03-22 18:26:50,698] C02PV7NSG8WP/INFO/locust.runners: Hatching and swarming 1 clients at the rate 1 clients/s...
Name # reqs # fails Avg Min Max | Median req/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
Total 0 0(0.00%) 0.00
[2018-03-22 18:26:50,699] C02PV7NSG8WP/INFO/stdout: hello from taskset on_start
[2018-03-22 18:26:50,699] C02PV7NSG8WP/INFO/stdout:
[2018-03-22 18:26:51,703] C02PV7NSG8WP/INFO/locust.runners: All locusts hatched: BlazeDemoUser: 1
[2018-03-22 18:26:51,703] C02PV7NSG8WP/INFO/locust.runners: Resetting stats
Name # reqs # fails Avg Min Max | Median req/s
--------------------------------------------------------------------------------------------------------------------------------------------
POST /reserve.php?toPort=Buenos+Aries&fromPort=Paris 1 0(0.00%) 140 140 140 | 140 0.00
--------------------------------------------------------------------------------------------------------------------------------------------
Total 1 0(0.00%) 0.00
[2018-03-22 18:26:53,268] C02PV7NSG8WP/INFO/locust.runners: All locusts dead
[2018-03-22 18:26:53,268] C02PV7NSG8WP/INFO/locust.main: Shutting down (exit code 0), bye.
Name # reqs # fails Avg Min Max | Median req/s
--------------------------------------------------------------------------------------------------------------------------------------------
POST /reserve.php?toPort=Buenos+Aries&fromPort=Paris 2 0(0.00%) 139 139 140 | 140 0.00
--------------------------------------------------------------------------------------------------------------------------------------------
Total 2 0(0.00%) 0.00
Percentage of the requests completed within given times
Name # reqs 50% 66% 75% 80% 90% 95% 98% 99% 100%
--------------------------------------------------------------------------------------------------------------------------------------------
POST /reserve.php?toPort=Buenos+Aries&fromPort=Paris 2 140 140 140 140 140 140 140 140 140
--------------------------------------------------------------------------------------------------------------------------------------------
我错过了什么?提前谢谢!
【问题讨论】:
标签: locust