如何解决蝗虫-如何传递不同的主机地址
我们在同一个班级下有两个任务,都指向不同的主机。
示例: 指向主机的第一个任务(创建新令牌)-HTTP://xyz.abc.new 指向主机HTTP://xyz.abc.old
的第二项任务(创建新的旧令牌)
import time
from locust import User,HttpUser,task,between,SequentialTaskSet
class LoginTaskSet(SequentialTaskSet):
@task
def generate_token(self):
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
launch_response_new = self.client.post("/oauth2/access?grant_type=password&username=abcd@xyz.com&password=SWr5q3ghhhSd",headers=headers,name = "Create a new token")
print("Launch - Response body: {}".format(launch_response_new.text))
@task
def generate_old_token(self):
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
launch_response_old = self.client.post("/oauth/access?grant_type=password&username=abcd@xyz.com&password=SWr5q3ghhhSd",name = "Create a new token- old")
print("Launch - Response body old: {}".format(launch_response_old.text))
class Login(HttpUser):
tasks = [LoginTaskSet]
wait_time = between(1,2)
如何在每个请求中发送主机值?如何在不传递宿主值的情况下运行蝗虫?
解决方法
您可以在客户呼叫中为其提供完整的URL。当端点以host
开头时,它仅应使用您提供的/
。因此,您不仅可以"/oauth2/…"
,还可以"http://xyz.abc.new/oauth2/..."
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。