【问题标题】:Gatling make one scenario run once in a chain of scenariosGatling 让一个场景在一系列场景中运行一次
【发布时间】:2020-02-06 08:52:39
【问题描述】:

我有一个场景,我必须执行某些步骤。但我不希望用户多次登录。所以我链接了场景,但登录仍然发生多次。有没有办法限制部分链只运行一次?

class CreateUserSimulation extends Simulation {
val login = Login.getExec()
val userCreate = UserCreate.getExec("basic")
val userJourney = scenario("User Journey")
    .exec(login)
    .exec(userCreate)

setUp(      
    userJourney.inject(constantConcurrentUsers(10) during (2 seconds))
).protocols(Params.httpProtocol)

}

【问题讨论】:

  • “我不希望用户多次登录”是什么意思? Gatling 将为不同的用户运行场景(10 x 秒超过 2 秒)。这意味着在运行此方案时您应该会看到 20 次登录。
  • 我想使用相同的凭据(cookie 等)来创建 UserCreate exec
  • 您提出的是用户登录然后同时发出大量请求的情况。这真的很好地反映了您系统中发生的情况吗?

标签: scala gatling


【解决方案1】:

你需要创建一个变量来说明你是否在系统中

val userJourney = scenario("User Journey")
.exec(_.set(isLogin, "0"))
.doIf(session => session("isLogin").as[String].equals("0")) {
  exec("login")
    .exec(_.set("isLogin", "1"))
}
.exec(userCreate)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多