【问题标题】:Feeder value not updated in gatling test加特林测试中未更新馈线值
【发布时间】:2020-03-23 16:31:17
【问题描述】:

我是 scala 和 gatling 的新手。我正在尝试从 feeder 获取值并将 zip 文件发布到 service 。但是 ${extensionId} 没有用获取的值更新,而是保持为 ${extensionId} 。有人可以帮我知道如果我在这里错过了一些东西。

          def installExtension() =
            exec(http("template - Install Extension")
              .post(url + "/v1/extensions")
              .basicAuth("jack", "password")
              .headers(namespaceHeader)
// using testUtils to get InputStream conte
              .body(InputStreamBody(TestUtils.toStream(hashMap.get("${extensionId}").getOrElse(null))))
              .check(status.is( 201)))


 class extmgrSimulations extends Simulation {

          val extensionIds = csv(s"${Configuration.dataDirectory}/extensionId.csv").circular


          val extMgrScenerio = scenario("extensionMgr - Scenario")
            .during(Configuration.duration) {
              exitBlockOnFail(
                group("load-test") {
                  exec(
                    pace(Configuration.paceFrom, Configuration.paceTo),
                    feed(extensionIds),feed(extensionIds)
                      randomSwitch(
                      50.00 -> group("Install and delete") {
                        exec(
                          extmgrChain.installExtension(),
                          extmgrChain.deleteExtension(),
                        )
                      },
                      50.00 -> extmgrChain.listExtension()
                    )
                  )
                }
              )
            }

【问题讨论】:

    标签: scala gatling scala-gatling


    【解决方案1】:

    那是行不通的。 Gatling EL(字符串中的 ${} 语法)在任何地方都不能神奇地工作。这在documentation 中有解释。

    警告

    此表达式语言仅适用于传递给 Gatling DSL 方法的字符串值。当 Gatling 模拟被实例化时,此类字符串仅被解析一次。

    例如 queryParam("latitude", session => "${latitude}") 不起作用,因为参数不是字符串,而是返回字符串的函数。

    另外,queryParam("latitude", "${latitude}".toInt) 不会,因为 toInt 会在将参数传递给 queryParam 方法之前发生。

    这里的解决方案是传递一个函数:

    session => session("latitude").validate[Int].

    【讨论】:

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