运行多个用户时出现加特林错误 - 'httpRequest-2'执行失败:未定义名为 'access_token' 的属性



im是Gatling的新手,一直在尝试设置一个测试,让我的用户登录,获取访问令牌,然后使用该令牌执行一些简单的获取请求。有1-2个用户工作得很好,但是一旦我开始增加用户,我就会收到这个错误的垃圾邮件:

[ERROR] i.g.h.a.HttpRequestAction - 'httpRequest-2' failed to execute: No attribute named 'access_token' is defined

我想这可能与我保存和使用访问令牌的方式有关?

class GatlingTest extends Simulation {
val httpProtocol = http
.baseUrl("https://myurl.com/api/v1")
.inferHtmlResources(BlackList(""".*.js""", """.*.css""", """.*.gif""", """.*.jpeg""", """.*.jpg""", """.*.ico""", """.*.woff""", """.*.woff2""", """.*.(t|o)tf""", """.*.png""", """.*detectportal.firefox.com.*"""), WhiteList())
.acceptLanguageHeader("en-GB,en;q=0.5")
.upgradeInsecureRequestsHeader("1")

object GetUserData {
val userData = exec(http("Get_User_Data")
.get("/user")
.header("Authorization", "Bearer ${access_token}"))
.pause(1)
}
object GetUserInfo {
val userInfo = exec(http("Get_User_Info")
.get("/userInfo")
.header("Authorization", "Bearer ${access_token}")
.header("Accept", "application/json"))
.pause(1)
}
object Login {
val sentHeaders = Map("api_key" -> "nnxzv336wt2374h6zw5x24qd", "Content-Type" -> "application/x-www-form-urlencoded", "Accept" -> "application/json")
val login = exec(http("Login_User")
.post("/login")
.basicAuth("username", "password")
.headers(sentHeaders)
.body(StringBody("grant_type=password&username=username@username.local&password=12345"))
.check(jsonPath("$.access_token").saveAs("access_token"))

)
}
val user = scenario("User").exec(Login.login).exec(GetUserData.userData, GetUserInfo.userInfo)
setUp(
user.inject(
rampUsers(5).during(2.seconds),
).protocols(httpProtocol)
)
}

我已经在get请求中添加了Authorization Bearer,就像我提到的那样,它确实有效,但只要有3个以上的用户参与,我就会收到错误。

这意味着login请求失败,因此用户无法在那里捕获access_token

最新更新