[英]How to fail a Gatling test from within “exec”?
带有 exec 链的 Gatling 场景。 请求后,返回的数据被保存。 后来它被处理,根据处理结果,它应该失败或通过测试。
这似乎是最简单的可能场景,但我找不到任何可靠的信息如何从 exec 块中使测试失败。 断言打破了场景,看起来像是加特林(如:异常抛出不仅没有通过测试)。
例子:
// The scenario consists of a single test with two exec creating the execChain
val scn = scenario("MyAwesomeScenario").exec(reportableTest(
// Send the request
exec(http("127.0.0.1/Request").get(requestUrl).check(status.is(200)).check(bodyString.saveAs("MyData")
// Process the data
.exec(session => {
assert(processData(session.attributes("MyData")) == true, "Invalid data");
})
))
在“监护人失败,正在关闭系统”的某处场景之上。
现在这似乎是一个有用的、经常使用的事情——我可能遗漏了一些简单的东西。 怎么做?
您必须遵守 Gatling API。
processData
,通常在转换可选步骤中。你在寻找类似的东西吗
.exec(http("getRequest")
.get("/request/123")
.headers(headers)
.check(status.is(200))
.check(jsonPath("$.request_id").is("123")))
因为编辑队列已经满了。
这已经在新版本的 Gatling 中得到解决。 版本 3.4.0
他们补充说
exitHereIf("${myBoolean}")
exitHereIf(session => true)
如果条件成立,让用户从这一点退出场景。 条件参数是一个 Expression[Boolean]。
我使用exitHereIfFailed
实现了一些听起来就像你想要完成的东西。 我通常在虚拟用户尝试登录后使用它。
exitHereIfFailed
是这样使用的
val scn = scenario("MyAwesomeScenario")
.exec(http("Get data from endpoint 1")
.get(request1Url)
.check(status.is(200))
.check(bodyString.saveAs("MyData"))
.check(processData(session.attributes("MyData")).is(true)))
.exitHereIfFailed // If we weren't able to get the data, don't continue
.exec(http("Send the data to endpoint 2")
.post(request2Url)
.body(StringBody("${MyData}"))
如果exitHereIfFailed
之前的任何检查失败,则此场景将在exitHereIfFailed
处exitHereIfFailed
中止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.