2017-11-09 32 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 = EXEC(セッション=> session.set( "randomN"、ThreadLocalRandom.current.nextInt(999999999))) .exec(HTTP( "ユーザーの作成" ) .post( "/ユーザ") .body(StringBody( "" "{ "メール": "${randomN}@company.com"}" "")))} 私はこれを掻き一緒に私が見つけたコードのいくつかの他のビットのうち。これはうまくいきますが、これがあなたのソリューションとどのように似ているのか不思議です。 –

関連する問題