在Locust中使用不同的多个主机名

huangapple go评论74阅读模式
英文:

Different multiple hostnames in locust

问题

如何在Locust脚本中使用多个主机名(URL)?我有一个场景,需要通过访问不同的API获取令牌,并在我的脚本中使用该令牌来访问其他API。

我尝试使用Locust中的事件,但未能获得预期的结果。

英文:

How to use the multiple hostnames(URL) in the locust script? I have a scenario where i need to get a token by hitting different API and use that token in my script for hitting the other API

I tried using events in locust but not able to get the expected result.

答案1

得分: 1

host 在 Locust 中仅仅是一种方便的因素,允许你在一次定义基本 URL,然后在此基础上定义相对 URL,如果你选择这样做,可以使代码更加简洁,有时更加精简,同时也可以在运行时更改基本 URL(比如不同的测试环境)。

然而,使用 host 和相对 URL 是可选的。Locust 的所有客户端都可以接受完整的 URL。

你可以随时通过传入完整的 URL 来调用完全不同主机上的不同 API。你可以在代码中进行任何决策,比如拥有一个预定义的主机1与tokenAPI1相关联的字典,主机2与tokenAPI2相关联,等等。或者根据一些规则或命名约定构建一个 URL 并使用它。这可以在单个 task 中完成,根据 host 调用一个 API,然后使用完整 URL 调用另一个位于其他服务器上的 API。这都无关紧要;Locust 将运行你提供的任何代码。你看到的文档和示例通常只是帮助引入 Locust 概念的基本起点,但不必局限于基础内容。

英文:

host in Locust is just a convenience factor, allowing you to give some base URL once and then define relative URLs off of that if you choose to make things a bit easier, less verbose in some cases, and give you the ability to change the base URL (such as for different testing environments ) at runtime.

However, using host and relative URLs is optional. All of Locust's clients can take a full URL.

You can call a different API on a totally different host anytime you want by passing in the full URL. And you can do whatever you want in code to make that determination, like having a predefined dictionary of host1 relating to tokenAPI1, host2 to tokenAPI2, etc. Or building a URL based on some rules or naming convention and using that. And this can all be done in a single task, calling one API based on host and another with a full URL to another server elsewhere. It doesn't matter; Locust will run whatever code you give it. The docs and examples you see are often basic starting points to help introduce the Locust concepts to people but don't have to be limited to the basics in any way.

huangapple
  • 本文由 发表于 2023年3月9日 16:13:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75681927.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定