Making gatling generate random data per request using a feeder
Asked Answered
A

2

6

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)
}
Adis answered 17/12, 2018 at 18:25 Comment(0)
M
2

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.

Mosley answered 19/12, 2018 at 14:48 Comment(1)
Ran into the same thing. Suspected that might be the case... it's an easy mistake to make, apparently. Thank you for the explanation!Pulsimeter
T
-1

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)))
Throwback answered 19/12, 2018 at 1:7 Comment(1)
The "users" here indicates parallelism, and not number of executions. The . forever is what tells gatling to repeat the scenario until the duration is reached. More info here - gatling.io/docs/2.3/general/simulation_setup/#throttlingAdis

© 2022 - 2024 — McMap. All rights reserved.