【发布时间】:2022-02-02 01:02:43
【问题描述】:
如何在 3 小时测试期间每 15 分钟在 gatling(用 scala 编写)中刷新我的不记名 (aouth2) 令牌?
我能够获得我的令牌,但我无法在场景中每 15 分钟应用一次。
def getXYZ() = {
exec(
http("Get all xyz")
.get("/xyz/v1/abc")
)
}
val authTimeout = 20.seconds
val safetyMargin = 5.seconds
val executionTime = 2.hours
val tokenTimeout: ChainBuilder = exec(session => session.set("timeout", authTimeout.fromNow))
val printSession: ChainBuilder = exec { session => println(session)
session
}
def refreshAccessToken(): ChainBuilder = {
exec(tokenTimeout)
doIf(session => {
session("timeout").as[Deadline].timeLeft <= safetyMargin
}) {
exec(
http("Refresh Access Token")
.post(url)
.formParam("grant_type", "client_credentials")
.formParam("scope", scope)
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", s"Basic $base64EncodedCredentials")
.check(jsonPath("$.access_token").find.saveAs("accessToken"))
)
.exec(printSession)
}
}
val scn = scenario("Scenario: Load Simulation With rampingUp Users")
.exec(session => {
val mytoken = session("accessToken") // -->Trying the capture the token here
println(mytoken.as[String])
session
})
.exec(getXYZ())
.pause(5)
setUp(
scn.inject( ..... etc ...)
【问题讨论】:
标签: testing oauth-2.0 load bearer-token scala-gatling