2017-11-09 1 views
0

Gatling을 사용하여 제품의 성능 문제를 테스트하기 위해 많은 사용자를 생성하고 있습니다. 고유 한 필드 (예 : '이메일')가있는 사용자를 동적으로 생성 할 수 있어야합니다. 그래서 임의의 숫자를 생성하고 사용하고 있지만 매번 다시 인스턴스화되지 않으므로 전자 메일은 첫 번째 패스에서만 고유합니다.Scala에서 Gatling을 사용하여 동적 POST/사용자 호출 만들기

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": "[email protected]" }"""))) 
    } 
} 

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

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

어디에서 임의 번호를 정의해야합니까? 어떻게 그것을 createUser에 전달할 수 있습니까?

답변

1

사용하십시오 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) 

... 
+0

발는 createUser = 간부 (세션 => session.set ("randomN", ThreadLocalRandom.current.nextInt (999999999))) .exec (HTTP ("사용자 만들기") .post ("/ 사용자") .body (StringBody ("" "{"이메일 ":"${randomN}@company.com "}" ""))) } 나는이 긁힌 내가 찾은 몇 가지 다른 코드들과 함께. 작동하지만, 이것이 당신의 솔루션과 어떻게 비교되는지 궁금합니다. –

관련 문제