Scala 如何使用gatling每次与随机用户登录?

Scala 如何使用gatling每次与随机用户登录?,scala,performance-testing,load-testing,gatling,Scala,Performance Testing,Load Testing,Gatling,我的场景是,我必须为创建一个脚本,随机抽取10个用户进行登录和注销我编写的代码登录同一用户10次,但不使用随机数。如何做到这一点 下面是我的代码输出相同的用户登录10次,而不是采取不同的用户 // Login and Logout random users import scala.concurrent.duration._ import java.util.concurrent.ThreadLocalRandom import io.gatling.core.Predef._ import i

我的场景是,我必须为创建一个脚本,随机抽取10个用户进行登录和注销我编写的代码登录同一用户10次,但不使用随机数。如何做到这一点

下面是我的代码输出相同的用户登录10次,而不是采取不同的用户

// Login and Logout random users
import scala.concurrent.duration._
import java.util.concurrent.ThreadLocalRandom
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class random extends Simulation {

 val testServerUrl = System.getProperty("Url", "https://url")
 val username = System.getProperty("username", "TestUser")
 val password = System.getProperty("password", "password")
 val userCount = Integer.getInteger("userCount", 10).toInt
 val startNum = Integer.getInteger("EndNumber", 1).toInt
 val endNum = Integer.getInteger("EndNumber", 100).toInt

 val httpProtocol = http
 .baseURL(testServerUrl)

 val scn = scenario("random")
 .exec(http("Login")
 .post("/security_check")
 .headers(headers_9)
 .formParam("j_username", username + ThreadLocalRandom.current.nextInt(startNum, endNum))
 .formParam("j_password", password)
 .resources(
 http("Fetch_IDs")
 .get("/desktop/s_nav.jsp")
 .check(regex("""current_account_id=(\d+)""").saveAs("accountID"))
 .check(regex("""current_workspace_id=(\d+)""").saveAs("workspaceID"))
 .headers(headers_5)
 ))

 .exec(http("Logout")
 .post("/logoutcontroller")
 .headers(headers_9)
 .formParam("action", "logout")
 .formParam("undefined", "")
 .formParam("current_account_id", "${accountID}")
 .formParam("current_workspace_id", "${workspaceID}"))

 setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}

问题在于,在生成场景时,场景val中的随机生成器只被调用一次

您要做的是使用一个feeder,它在场景的每次执行中注入随机值

Gatling提供了一份非常好的文档,其中包含馈线示例,您可以在此处找到:

这里(步骤03):

问题在于,场景val中的随机生成器在生成场景时只调用一次

您要做的是使用一个feeder,它在场景的每次执行中注入随机值

Gatling提供了一份非常好的文档,其中包含馈线示例,您可以在此处找到:

这里(步骤03):

.formParam("j_username", session => username +  ThreadLocalRandom.current.nextInt(endNum))