【发布时间】:2019-12-23 14:00:24
【问题描述】:
为了模拟 locust 中的特定迭代次数,我使用如下简单的代码流:
class NcsoTest(TaskSet):
REQ_HEADER = {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "860",
"Content-Type": "application/json",
"User-Agent": "python-requests/2.21.0",
}
@seq_task(1)
def user_workflow(self):
locrunner = MasterLocustRunner()
for i in range(1, 100, 1):
self.send_post_request()
self.send_get_request()
Singleton.logger().info("Test Number reached. Stopping Locust.")
#runners.locust_runner.quit()
locrunner.quit()
def send_post_request(self):
response = self.client.post("/api/v2/services", data=Singleton.json_body, headers=NcsoTest.REQ_HEADER)
print response
def send_get_request(self):
response = self.client.get("/api/v2/services", headers=NcsoTest.REQ_HEADER)
print response
class NcsoLoad(HttpLocust):
max_wait = 300
min_wait = 300
sleep_time = 10
task_set = NcsoTest
为了运行这个测试,我使用带有以下参数的命令:
--host https://10.123.123.123 --min_wait_time 300 --max_wait_time 300 --num_clients 1 --hatch_rate 1 --test_time 5m
虽然,我可以执行 100 个请求,但如果这 100 个请求在 5 分钟前完成,locust runner 会不断给出错误,指出 MasterLocustRunner 需要更多参数,即 locust_class 和选项(我在 locust 命令中指定)
如果我取消注释“runners.locust_runner.quit()”并注释“locrunner.quit()”,测试会继续等待,直到运行时结束后来自 Master 的优雅终止调用。
我想知道的是,如何手动/结束优雅地终止蝗虫 - 主从。
【问题讨论】:
标签: locust