在 Gadling 中添加 gRPC 请求的退出

问题描述 投票:0回答:1

我有一个 bidiStream 配置如下

.exec(
    bidiStream_conf
      .start("#{payload}")
      .header(metadataObject.Authorization)(s"Bearer ${Key}")
      .extract(_.pk.some)(_ saveAs "var")
      .sessionCombiner(SessionCombiner.pick("var"))
      .endCheck(statusCode is Status.Code.OK)
  )
.exitHereIfFailed
.exec(REST_req)
.exec(bidiStream_conf.complete)
.exec(bidiStream_conf.reconciliate(waitFor = NextMessage))

我想在流失败时强制退出 V.User,所以我传递了一个假密钥,当我运行这个时,我得到了以下日志

gRPC stream completion:
status=
PERMISSION_DENIED, description: code = E3014, message = Token is invalid!
trailers=
content-type: application/grpc
<<<<<<<<<<<<<<<<<<<<<<<<<
15:45:32.700 [DEBUG] c.g.p.g.g.s.BidiStreamCall - Client issued message but stream bidiStream_conf already completed

================================================================================
2023-11-30 15:45:34                                           5s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=2      KO=1     )
> bidiStream_Req                                           (OK=0      KO=1     )
> REST_Req                                                 (OK=1      KO=0     )
---- Errors --------------------------------------------------------------------
> grpcStatusCode.find.is(OK), but actually found PERMISSION_DENI      1 (100.0%)
ED

看到下面的 REST API 仍在执行,我想我做错了

exitHereIfFailed
,在这种情况下我该如何正确执行,以强制 V.User 完全停止整个场景?

scala grpc gatling
1个回答
0
投票

要在 gRPC 流失败时强制退出整个场景,可以使用 Gadling 的 exitBlockOnFail 方法。 检查此代码。

.exec(
  bidiStream_conf
    .start("#{payload}")
    .header(metadataObject.Authorization)(s"Bearer ${Key}")
    .extract(_.pk.some)(_ saveAs "var")
    .sessionCombiner(SessionCombiner.pick("var"))
    .endCheck(statusCode is Status.Code.OK)
 )
.exitHereIfFailed // Remove this line
.exitBlockOnFail( // Add this block
    exec(REST_req),
    exec(bidiStream_conf.complete),
    exec(bidiStream_conf.reconciliate(waitFor = NextMessage))
 )
© www.soinside.com 2019 - 2024. All rights reserved.