我需要实现下一个逻辑:
1)执行on_start方法(例如login)
2)执行下一个任务(task_2)5次
3)之后执行下一个任务(task_3)10次
返回on_start等...
所以最后我需要登录:1,任务_2:5,任务_3:10。(每1次登录5次和10次)
我尝试用下面的代码来实现它:
class MyTaskSet(TaskSequence):
def on_start(self):
login()
@seq_task(1)
def task_2(self):
print('Need to be executed 5 times after 1 login')
@seq_task(2)
def task_3(self):
print('Need to be executed 10 times after 1 login')
class LocustUser(HttpLocust):
host = http://localhost
task_set = MyTaskSet
Run Code Online (Sandbox Code Playgroud)
性能大师可以帮我解决这个逻辑吗?
我有 locustio 文档中的下一个代码:
from locust import HttpLocust, TaskSet, between
def login(l):
l.client.post("/login", {"username":"ellen_key", "password":"education"})
def logout(l):
l.client.post("/logout", {"username":"ellen_key", "password":"education"})
def index(l):
l.client.get("/")
def profile(l):
l.client.get("/profile")
class UserBehavior(TaskSet):
tasks = {index: 2, profile: 1}
def on_start(self):
login(self)
def on_stop(self):
logout(self)
class WebsiteUser(HttpLocust):
task_set = UserBehavior
wait_time = between(5.0, 9.0)
Run Code Online (Sandbox Code Playgroud)
在蝗虫日志和蝗虫网络(localhost:8089)中我看到了接下来的任务
- /login
- /logout
- /
- /profile
Run Code Online (Sandbox Code Playgroud)
但是,如果我需要在一项任务中包含很少的请求并从完整的任务(而不是 1 个请求)中获取度量,该怎么办?
我想看到的是:
- login
- logout
- index
- profile
Run Code Online (Sandbox Code Playgroud)
我想查看任务名称而不是请求 url。在 Jmeter 中,我可以在一个操作中插入几个请求并获取操作时间(而不是请求)。