【问题标题】:Locust- how to pass different host address蝗虫-如何传递不同的主机地址
【发布时间】:2020-09-20 16:33:09
【问题描述】:

我们在同一个类下有两个任务,都指向不同的主机。

示例: 第一个任务(创建新令牌)指向主机 - 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", 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)

如何在每个请求中发送主机值?如何在不传递主机值的情况下运行蝗虫?

【问题讨论】:

    标签: locust


    【解决方案1】:

    您可以在客户端调用中为其提供完整的 URL。当您的端点以/ 开头时,它应该只使用您提供的host。因此,您可以使用"http://xyz.abc.new/oauth2/...",而不只是"/oauth2/…"

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多