scala - 生成身份验证令牌并在 Gatling 的整个会话中使用它
问题描述
我有一个场景,我正在点击 keyCloak 请求并将令牌用作其他 HTTP 请求中的标头。
我的问题是对于 100 个用户,它会生成 100 个令牌,因此我正在寻找仅命中一次 keyCloak 请求并且在整个性能运行过程中使用令牌的解决方案。
供参考的示例代码片段:
scenario("CMS service")
.exec(KeycloakToken.request(conf))
.exec(getOffers.request(conf))
.exec(offerById.request(conf))
解决方案
使用馈线https://gatling.io/docs/current/session/feeder/。
1) 创建馈线
val feeder = Iterator.continually(Map("token" -> "dG9rZW4="))
2) 将馈线添加到场景
scenario("CMS service")
.feed(feeder)
.exec(...)
3) 通过 Gatling EL https://gatling.io/docs/current/session/expression_el传递值
在您的 http 请求中添加令牌
http(...)
.post(...)
.header("your token header", "${token}")
推荐阅读
- python - 如何在文件夹中找到相同的文件名,然后将重复项移动到 Python 中的不同文件夹?
- c - 如何在引导程序中使用 fexec 编译和运行 C 程序?
- android - Android API 31,如何获取SSID?
- python - 我可以让 for 循环永远运行吗?(Python)
- oracle-adf - 收到所需文件集后触发触发
- python - 以特定顺序将图像加载到列表中
- android-studio - 使用 Android Studio 进行 Oculus 开发的最佳示例应用?
- angular - Angular 拦截器请求因 strict-origin-when-cross-origin 而失败
- kotlin - 是否可以在 scope.cancel 之后接收发射?
- java - 我正在制作一个 Minecraft Mod,我收到错误“mods.toml 缺少 modid mymod 的元数据”