Locust-如何传递不同的主机地址
Locust- how to pass different host address
我们在同一个 class 下有两个任务,都指向不同的主机。
Example:
First task (Create a new token) pointing to host - HTTP://xyz.abc.new
Second task (Create a new token-old) pointing to host- 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", headers=headers,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/..."
.
我们在同一个 class 下有两个任务,都指向不同的主机。
Example: First task (Create a new token) pointing to host - HTTP://xyz.abc.new Second task (Create a new token-old) pointing to host- 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", headers=headers,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/..."
.