I would like to refresh the token for every 5 minutes, however as soon as i start running the script it prints I am inside exec method that is inside doIf method below.
not sure how it prints as soon as i run gatling test, since i do have the condition inside doIf method, I expected the statement to print (I am inside exec method) only when doIf condition is met. it only prints console.log and doesnt execute exec method after, when i search for Refresh token", in the log file, i dont find any api requests. Can you please advise how it prints I am inside exec method - as soon as the gatling test started, even before setup block starts executing.
Secondly, My understanding is that the token refresh exec method should execute when it nears 250 seconds fromNow, and when only 5 seconds left -safetyMargin ( 5 seconds less than 300) based on the condition in doIf below. but the exec method to refresh token is never executing, can you please advise what i am missing here.
val authTimeout = 300.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)
println(s"*************************************I am inside print session****************************")
session
}
def refreshAccessToken = scenario("Access Token Generation")
.exec(tokenTimeout)
doIf(session => {
println(s"*************************I am inside*****************************")
session("timeout").as[Deadline].timeLeft <= safetyMargin
}) {
println(s"***********************************I am inside exec method************************************")
exec(
http("Refresh token")
.post("https://www.odfo.com")
.basicAuth("fbkfeb", "249r3849t")
.queryParam("grant_type", "client_credentials")
.headers(header)
.check(status.is(200)).check(jsonPath("$.access_token").exists.saveAs("access_token"))
)
.exec(printSession)
}
private val submitOrders: ScenarioBuilder =
scenario("order Submission")
.exec(refreshAccessToken)
.exec(Submission()) --> this method submits api request with 300000 records, that has to capture the refresh token from the session.
setUp(
Orders.inject(
nothingFor(1),
atOnceUsers(1),
).andThen(openOrders.inject(nothingFor(1),
atOnceUsers(1)).
andThen(submitOrders.inject(nothingFor(1),
atOnceUsers(1),
rampUsers(10).during(50))).
andThen(closeOrders.inject(nothingFor(1),
atOnceUsers(1)))))