Search code examples
gatlingscala-gatling

How can I refresh injected values


I have created a Gatling project that contains many different data sets. The reason for this, I want to include randomness and uniqueness with every SOAP request I throw at my service. Example: One data set has id numbers and another data set has colors. I want to inject these values in my request that I send to my webservice.

When I start up gatling, it generates requests with random values (like expected) but then reuses the same id and color combination. If possible, I would like to send a different request everytime (for example) id: 001 and color: blue. Then send a request with id: 001 and color: red. Right now it just resends id: 001 and color: blue.

I have id.scala and color.scala files with hundreds of lines and a xml request file so combinations should be endless.

val id = jsonFile("data/id.json").circular
val color = jsonFile("data/color.json").circular


def updateIdWithColor() = {
    .exec(http("Add Color")
      .post("/")
      .body(ElFileBody("requests/addcolor.txt"))
      .check(status.is(200)))
  }


val scn = scenario("Load Testing")
    .feed(id)
    .feed(color)
    .forever() {
      exec(updateIdWithColor())
    }

  setUp(
    scn.inject(
      nothingFor(5 seconds),
      atOnceUsers(5),
      rampUsers(userCount) during(rampUpUsersOverSeconds seconds)
    ).protocols(httpConf)
  ).maxDuration(testDuration minutes)
    //.assertions(
    //  global.responseTime.max.lt(2000),
    //  global.successfulRequests.percent.gt(99.9),
    //)
}

Is there a way I can REFRESH id to color combination so I can send a different request every time? If I run for 15 minutes, it just sends a SOAP xml request with 001 -> blue for 15 minutes.

Please let me know if I can bring anything else. I am confident there is a method I can use (potentially) in the code blocks I provided. I am just not aware. Thanks in advance!


Solution

  • You have to move your feeds inside your forever loop:

    val scn = scenario("Load Testing")
        .forever() {
          feed(id)
            .feed(color)
            .exec(updateIdWithColor())
        }