Hi,
I have been struggling with this for some time now. I have read many similar topics that do not seem to answer my specific issue, so I’ll ask here:
The problem I have is that I define a CSV feeder and try to pass the column values to a body. In my specific situation I use an expression function because the same body also needs to invoke a function (randVals()) every time. Next to this, I also set a static val beginDate that is set properly. Only with the CSV feeder, I don’t get the values in “foo” and “bar”. If I declare the vals foo and bar as a string I can set a static value like with beginDate.
I think the problem is with my understanding of how sessions are handled, which is something I struggle to understand atm. I want to set up my test in a way that I can define calls first and easily add and remove calls from the actual scenario execution which is why I have chosen this approach.
I have broken my test down to the minimum below. Any insights will be much appreciated.
`
class Loadtest extends Simulation {
val beginDate = date.format(DateTimeFormatter.ISO_LOCAL_DATE)
def randVals(): String = { //somefunction }
val data = csv(“feeder.csv”).circular //=> contains columns “foo” and “bar”
object RegularFlow {
val foobar =
exec(http(“POSTfoobar”)
.post("/api")
.headers(headers_2)
.header(“Authorization”, “Bearer ${accesstoken}”)
.body(StringBody(session => s"""
{
“body”:[{“id”:"${randVals()}",
“foo”: “${foo}”,
“bar”:"${bar}",
“date”:"${beginDate}"}]}
“”")).asJSON)
}
//Execute scenario
val scn = scenario(“Loadtest”)
.feed(data)
.exec(
RegularFlow.foobar
)
setUp(scn.inject(constantUsersPerSec(1) during(10 seconds))).protocols(httpProtocol)
}
`