from locustimport HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
#def on_start(self):
#self.client.post("/login", {"username": "admin","password": "admin"})
@task(1) //@task() 装饰该方法为一个任务,1表示一个Locust实例被挑选执行的权重,数值越大,执行频率越高。
def detail(self):
self.client.get("http:_name=&term_name=&file_name=%E6%96%87%E4%BB%B6&page_size=10&page_no=1&sort=desc&order=update_time&user_id=admin&contents_ids=&secret=&&null") 接口地址
@task(1)
def question(self):
self.client.get("q_text=%E5%93%88%E5%93%88%E6%B5%8B%E8%AF%95&page_size=10&page_no=1&sort=desc&order=update_time&user_id=admin&contents_ids=&&null")
@task(1)
def new(self):
self.client.get("name=%E6%89%B9%E9%87%8F&news_type=&news_effect=&page_size=10&page_no=1&sort=desc&order=update_time&&null")
class WebsiteUser(HttpLocust): //WebsiteUser()类用于设置性能测试
task_set=UserBehavior //task_set :指向一个定义了的用户行为类。
host ="http://127.0.1.1:1804" //需要测试的地址ip
min_wait =1000
max_wait =5000
WebsiteTasks中的on_start(只执行一次),作为初始化;
max_wait/min_wait: 每个用户执行两个任务间隔时间的上下限(毫秒),具体数值在上下限中随机取值,若不指定则默认间隔时间固定为1秒;