Search code examples
scalagatling

Gatling CSV feeder keeps getting the first value in the csv when using repeat() or during() and when using 1 virtual user


My question is similar with this one , but he didn't use looping, meanwhile I absolutely need to use it.

My CSV looks simply like this

myCSV.csv

Using Gatling 3.3.1 , I use 1 user and want to run and repeat a scenario using during() , but in each repetition the next CSV value should be taken in sequence. Once it reaches the last value, it should restart to the first value in the CSV.

My codes look like this

val myCSV = csv("data/myCSV.csv").eager.queue.circular

val theScenarioBuilder: ScenarioBuilder = scenario("Test Only")
  .feed(myCSV)
  .during(3 seconds) {
    exec(session => {
      println("myCSV:     " + session("id").as[String])
      session
    })

  }


setUp(
  theScenarioBuilder.inject(atOnceUsers(1))
).protocols(theHttpProtocolBuilder)

This will print myCSV: 1 a couple of times.
My expectation is myCSV: 1 , myCSV: 2 , myCSV: 3 , and so on.

The same when I tried using repeat() , I get the same problem, only myCSV: 1 will be printed.

val myCSV = csv("data/myCSV.csv").eager.queue.circular

val theScenarioBuilder: ScenarioBuilder = scenario("Test Only")
  .feed(myCSV)
  .repeat(3) {
    exec(session => {
      println("myCSV:     " + session("id").as[String])
      session
    })

  }

How can I grab different CSV value for each iteration?


Solution

  • You're calling feed outside of the repeat loop. How could you possibly get different records?

    val myCSV = csv("data/myCSV.csv").eager.circular // queue and circular are exclusive
    
    val theScenarioBuilder: ScenarioBuilder = scenario("Test Only")
      .repeat(3) {
        feed(myCSV)
        .exec(session => {
          println("myCSV:     " + session("id").as[String])
          session
        })
    
      }