Making gatling generate random data per request using a feeder

Viewed 1845

I'm trying to get gatling to create random data per POST request. I've followed a few posts on stackoverflow and other places. I came up with this scenario -

def randomUuid = UUID.randomUUID().toString
val feeder = Iterator.continually(Map("user" -> randomUuid))

def createPostRequest = {
  http("createuser")
    .post("http://jsonplaceholder.typicode.com/posts")
    .body(StringBody("${user}"))
    .check(status.is(201))
}

val scn = scenario("some load test")
  .feed(feeder)
  .forever(exec(createPostRequest))

setUp(scn.inject(atOnceUsers(1)))
  .maxDuration(20 minutes)

However, when I run this code it just calls my feeder once to create a single UUID and just re-uses the same UUID throughout the load test.

I created the code above after following this thread. I'm using gatling 2.2.5. Here's my sbt config -

import sbt._

object Dependencies {
  private val gatlingHighcharts = "io.gatling.highcharts" % "gatling- 
  charts-highcharts" % "2.2.5"                    % "test"
  private val gatlingTest =       "io.gatling"            % "gatling-test-framework"    % gatlingHighcharts.revision % "test"

  val gatlingDependencies = Seq(gatlingHighcharts, gatlingTest)
}
2 Answers

As you don't call feed inside a loop, typically your forever one, you will indeed only generate one single value per virtual user. If what you want is to have unique values per loop iteration, move the feed call inside the loop.

in your setUp, you're only creating one user - so your scenario is only getting executed once, meaning that 'feed' only occurs once before you start looping over your request.

change your scenario to be

val scn = scenario("some load test")
.feed(feeder)
.exec(createPostRequest)

and make your setUp (replacing 100 with whatever number of users you want)

setUp(scn.inject(atOnceUsers(100)))
Related