from locust import HttpLocust, TaskSet
def login(self):
params= {'name':'test','password':'test1','primary_email':'test667@gmail.com','primary_mobile_number':'9999999999','country_abbrev':'US'}
self.client.post(URL, data=params)
#The data parameter or json can both be used here. If it's a dict then data would work but for json replace data with json. For more information you can check out requests package as Locust internally uses requests only.
class UserBehavior(TaskSet):
tasks = {index: 2, profile: 1}
def on_start(self):
login(self)
def on_stop(self):
pass
@task
def try(self):
pass
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 5000
max_wait = 9000
要启动负载测试,请运行rocast-f rocast_files/my\u ocast_文件.pyhost=http://example.com其中host是您的IP。然后可以转到127.0.0.1:8089,选择要模拟的虚拟用户数。
在windows上,只有1024个用户。但是您可以使用蝗虫提供的主从架构的惊人支持。在
PS:在on_start方法中放入的任何内容对于每个用户只运行一次。因此,既然您想测试API的限制,您应该更喜欢在@task修饰符下添加该请求。在
希望这有帮助!:)