Is there a way to set repeat number dynamic?

Hi,

I was wondering if there’s a way to set repeat number dynamic, does it have to be hard coded, I was hope to get the repeat number from csv feeder.

For instance, my test needs to search for titles, I can set the repeat number to 5, but if the title length is less than 5, take the title length as the repeat number. The test needs to print out how many keystrokes to take to find a title.

Thanks!

Yes, as explained in the documentation, repeat parameter can be a hard coded value, an EL expression or a Session lambda: https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-repeat
In your case, passing a lambda is probably more appropriate as you want to do a math.min. Which version of Gatling do you use?

Thanks a lot for your quick reply.

I’m using version “1.4.2”, I tried session attribute before, somehow didn’t work.
Here’s my try out:

val titleFeeder = csv(GetProperties.topShowCsv)

scn = scenario(“Search titles by key stroke”).

repeat(titlesCount) {

feed(new QueryFeederKeyStroke(titleFeeder)).

exec((s: Session) => { println(s.getTypedAttributeInt); s })

exitBlockOnFail {

repeat((s: Session) => s.getTypedAttributeInt) {

feed(new QueryFeederKeys(keyFeeder)).

exec(

http(“Search by key stroke”).

get(Endpoints.search + “?${finalQueryString}”).

headers(GetProperties.sentHeaders).

check(status.is(200)) }

}

}

I was trying to get “length” from titleFeeder column “length”.

Can you please help to fix this or teach me how to pass lambda?

Thank you!

Where it titlesCount defined?

Then, what comes out of a csv feeder is Strings, so if you want your colums to be of a different type, you have to transform them.
In Gatling 2, there’s a convert method, but in Gatling 2, you have to do things manually.

csv(GetProperties.topShowCsv) is an Array[Map[String, String]], so you can do something like:

val titleFeeder = csv(GetProperties.topShowCsv).map(record => record.map {

case (“length”, string) => (“length”, string.toInt)
case cell => cell
}

I have
val titleFeeder = csv(GetProperties.topShowCsv)

val keyFeeder = tsv(GetProperties.keyStrokeCsv).circular

val titlesCount = csv(GetProperties.topShowCsv).length

defined at the beginning of the test, there’s no problem to get titlesCount, the problem is how to set keystroke count(“length”) as repeat number inside exitBlockOnFail block, like
repeat((s: Session) => s.getTypedAttributeInt), the “length” is something I was trying to get from titleFeeder, I’ve never made this statement work, the length is always empty.
I wonder if this is the correct way to get it?

BTW I have stick with Gatling 1, since my test rely on Scala 2.9 libraries, I heard Gatling 2 need to have Scala 2.10 plus ?

Thank you!

I have no idea why this wouldn’t work, sorry.

Please upgrade to 1.5.2 (Scala 2.9 based) and if you still have an issue, please provide a sample.

Cheers,

Stéphane