加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 如何在http请求中获取Gatling的随机URL?

发布时间:2020-12-16 18:46:10 所属栏目:安全 来源:网络整理
导读:我想在http请求中获取随机URL以获取Gatling 我的场景定义如下: import io.gatling.core.Predef._import io.gatling.http.Predef._import scala.concurrent.duration._import scala.util.Randomclass testSimulation extends Simulation { val httpConf = ht
我想在http请求中获取随机URL以获取Gatling

我的场景定义如下:

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.Random

class testSimulation extends Simulation {

  val httpConf = http.baseURL("OURURL")


  val scn = scenario("View HomePages")
                .exec(
                        http("Home page")
                                .get("/" + new Random().nextInt())
                              .resources(
                                      http("genericons.css").get("/wp-content/themes/twentyfifteen/genericons/generi$
                                      http("style.css").get("/wp-content/themes/twentyfifteen/style.css?ver=4.2.3"),http("jquery.js").get("/wp-includes/js/jquery/jquery.js?ver=1.11.2"),http("jquery-migrate.min.js").get("/wp-includes/js/jquery/jquery-migrate.min.j$
                                      http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$
                                      http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$
                                      http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$
                                      http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$
                                      http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$
                                      http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$
                              )
                )

  setUp(
      scn.inject
      (
      rampUsersPerSec(1) to(300) during(60 seconds),constantUsersPerSec(300) during(600 seconds)
      )
      .protocols(httpConf)
      )
}

我只生成一个随机数而不是每个请求一个.你知道怎么解决吗?谢谢 !

解决方法

你正在传递一个值,所以新的Random().nextInt在构建Simulation时只被调用一次.

你必须传递一个Expression,即一个函数.只有这样才会每次都进行评估.

.get(session => "/" + new Random().nextInt())

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读