import math
from locust import LoadTestShape
from locust import HttpUser,TaskSet,task,constant
class UserTasks(TaskSet):
@task
def get_root(self):
self.client.get('/')
class WebsiteUser(HttpUser):
wait_time = constant(0.5)
tasks = [UserTasks]
class StepLoadShaper(LoadTestShape):
'''
逐步加载实例
参数解析:
step_time -- 逐步加载时间
step_load -- 用户每一步增加的量
spawn_rate -- 用户在每一步的停止/启动
time_limit -- 时间限制
'''
setp_time = 30
setp_load = 10
spawn_rate = 10
time_limit = 60
def tick(self):
run_time = self.get_run_time()
if run_time > self.time_limit:
return None
current_step = math.floor(run_time /self.setp_time) +1
return(current_step * self.setp_load,self.spawn_rate)
应该不会,你看看是哪里出错了