Hi everyone, been struggling with this for over a week now, reading through every doc I could get my hands on and trying every combination - but I’m very new to Scala/Gatling/functional languages (normally C#, Python, etc), and I just don’t know enough to understand what I am looking for… (inherited this project from someone who knew scala much better)
Renaming / cleaning some stuff out for discussion purposes…
`
def http_req_first(member_index: String) = {
val member = created_members(member_index.toInt)
val first_name = member(“first_name”)
http(“/some/endpoint”)
.post(“/some/endpoint”)
.header(“Authorization”, “${header.Authorization}”)
.header(“Content-Type”, “application/json”)
.body(StringBody(
s"“”{
“firstName”: “${first_name}”
}“”“.stripMargin))
.check(status is 200)
.check(bodyString.saveAs(“json_response”))
.check(jsonPath(”$.returnId").saveAs(“returnId”))
}
val scn_simple_cycle = scenario(“MyScenario”)
.forever(“userCycleCounter”) {
feed(janus_users.circular)
.exec { session => session.set(“member_index”, next_member(session(“userCycleCounter”).as[Int])) }
.doIf(validation_on) {
exec( http_req_first(s"“”${member_index}“”") )
}.pause(execution_delay)
}
`
Fails (as we’d expect) with “not found: value member_index” because member_index isn’t defined as a normal variable
... exec( http_req_first(session("member_index")) ) ...
Fails with “not found: value session” because the session isn’t available
(if I don’t pass in a session variable then I get back a ChainBuilder(List(io.gatling.http.action.HttpRequestActionBuilder@2eae81f4)))
`
…
exec( session => http_req_first(session(“member_index”).as[String]) )
…
[or]
…
exec( session => {
http_req_first(session(“member_index”).as[String])
} )
…
`
Fails with "
type mismatch;
found : io.gatling.http.request.builder.HttpRequestBuilder
required: io.gatling.commons.validation.Validation[io.gatling.core.session.Session]
exec( session => http_req_first(session(“member_index”).as[String]) )
^
" which seems to want us to return session if we pass the session in (for the purpose of retrieving that variable we stored)
So a lot of places online recommend doing it this way
`
…
exec( session => {
http_req_first(session(“member_index”).as[String])
session
} )
…
`
which gets past there (returns a ChainBuilder(List(io.gatling.core.action.builder.SessionHookBuilder@7672e998))), and the value from session(“member_index”) gets passed along fine…
and then we fail at the end of the test-run with “Exception in thread “main” java.lang.ArithmeticException: / by zero”, which seems to be because we override session with the session we passed in, and lose the results of whatever happened in the http request? which Gatling seems to need for something? Probably wanted to see Validate[Session]?
I just don’t know what I’m looking at wrong / not quite getting what is happening under the hood. And I’ve tried dozens of other combinations and things, most of which I can’t even remember now
Why does passing in a session to an anonymous function require a session out? If I don’t pass a session in then http_req_first returns a ChainBuilder containing an HttpRequestActionBuilder which seems to be good enough, unless I pass a session in
What’s the correct way of doing this? What am I missing?