简体   繁体   中英

Creating dynamic POST /users calls with Gatling in Scala

I am using Gatling to generate a large number of users to test performance issues on my product. I need to be able to dynamically create users with unique fields (like 'email'). So, I'm generating a random number and using it, but it isn't being re-instantiated each time, so the email is only unique on the first pass.

object Users {

  def r = new scala.util.Random;
  def randNumb() = r.nextInt(Integer.MAX_VALUE)
  val numb = randNumb()

  val createUser = {
    exec(http("Create User")
    .post("/users")
    .body(StringBody(raw"""{"email": "qa_user_$numb@company.com" }""")))
  }
}

val runCreateUsers = scenario("Create Users").exec(Users.createUser)

setUp(
  runCreateUsers.inject(constantUsersPerSec(10) during(1 seconds))
).protocols(httpConf)

Where should I be defining my random numbers? How can I pass it into createUser?

Use a feeder :

object Users {
  val createUser = exec(http("Create User")
    .post("/users")
    .body(StringBody("""{"email": "qa_user_${numb}@Marqeta.com" }""")))
}

val numbers = Iterator.continually(Map("numb" -> scala.util.Random.nextInt(Int.MaxValue)))

val runCreateUsers = scenario("Create Users")
  .feed(numbers)
  .exec(Users.createUser)

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM