Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 在Gatling中为异步调用设置超时_Scala_Rest_Timeout_Load Testing_Gatling - Fatal编程技术网

Scala 在Gatling中为异步调用设置超时

Scala 在Gatling中为异步调用设置超时,scala,rest,timeout,load-testing,gatling,Scala,Rest,Timeout,Load Testing,Gatling,我正在使用Gatling对微服务架构进行一些负载测试。我正在测试两个REST服务;aPOSTon servicea开始执行引擎,而aGETon serviceB最终检索执行结果 使用asLongAs构造,我重试执行GETREST调用,直到结果未就绪。但是,我不想永远循环。我需要设置一个超时或最大尝试时间 我正在使用的代码摘录如下 scenario("my-scenario") .feed(feeder) .exec( http("post-to-A") .post("

我正在使用Gatling对微服务架构进行一些负载测试。我正在测试两个REST服务;a
POST
on service
a
开始执行引擎,而a
GET
on service
B
最终检索执行结果

使用
asLongAs
构造,我重试执行
GET
REST调用,直到结果未就绪。但是,我不想永远循环。我需要设置一个超时或最大尝试时间

我正在使用的代码摘录如下

scenario("my-scenario")
  .feed(feeder)
  .exec(
    http("post-to-A")
      .post("/execution")
      .body(StringBody(
        """{
          | "information": ${INFORMATION}
          |}""".stripMargin
      ))
     .asJSON
     .check(status.is(200))
  )
  .exec(_.set("result", ""))
  .asLongAs(session => session("result").validate[String].get != "") {
    exec(
      http("get-to-B")
        .get("/result")
        .check(status.is(200))
        .check(jsonPath("$.result").saveAs("result"))
    )
  }
scenario("my-scenario")
  .feed(feeder)
  .exec(
    http("post-to-A")
      .post("/execution")
      .body(StringBody(
        """{
          | "information": ${INFORMATION}
          |}""".stripMargin
      ))
     .asJSON
     .check(status.is(200))
  )
  .exec(_.set("result", ""))
  .tryMax(10) {
    asLongAs(session => session("result").validate[String].get != "") {
      exec(
        http("get-to-B")
          .get("/result")
          .check(status.is(200))
          .check(jsonPath("$.result").saveAs("result"))
      )
    }
  }
如何在上述代码中设置超时


多亏了大家。

而不是
您可以在
过程中使用
,在指定的时间内完成循环(查看使用情况)。

此外,您可能需要检查您的状况。到目前为止,只有当
result
的值不是空字符串时,才会执行循环,这意味着它根本不会被执行

在谷歌搜索了一段时间后,我发现很少有关于Gatling复杂场景开发的文档和示例。我的一篇得出类似结论的优秀文章如下:

由于缺少符合我要求的本地构造,我们可以构建的最佳解决方案是同时使用和方法

我问题中的代码如下所示

scenario("my-scenario")
  .feed(feeder)
  .exec(
    http("post-to-A")
      .post("/execution")
      .body(StringBody(
        """{
          | "information": ${INFORMATION}
          |}""".stripMargin
      ))
     .asJSON
     .check(status.is(200))
  )
  .exec(_.set("result", ""))
  .asLongAs(session => session("result").validate[String].get != "") {
    exec(
      http("get-to-B")
        .get("/result")
        .check(status.is(200))
        .check(jsonPath("$.result").saveAs("result"))
    )
  }
scenario("my-scenario")
  .feed(feeder)
  .exec(
    http("post-to-A")
      .post("/execution")
      .body(StringBody(
        """{
          | "information": ${INFORMATION}
          |}""".stripMargin
      ))
     .asJSON
     .check(status.is(200))
  )
  .exec(_.set("result", ""))
  .tryMax(10) {
    asLongAs(session => session("result").validate[String].get != "") {
      exec(
        http("get-to-B")
          .get("/result")
          .check(status.is(200))
          .check(jsonPath("$.result").saveAs("result"))
      )
    }
  }
Gatling将尝试调用第二个REST服务10次,直到调用成功。显然,您应该正确设计REST服务,响应不同于200的HTTP状态,直到无法达到结果为止

唯一的缺点是

请求失败被计入失败的请求中,在我们的案例中,这将极大地伪造结果


希望能有帮助。

好吧,我认为这不是一个可行的解决方案。在
期间使用
,我无法从与业务条件关联的循环中添加退出条件。