gatling - 模拟组失败的最佳方法
问题描述
我有一个我正在尝试模拟的场景,但我不确定最好/最惯用的方法。
我正在使用的应用程序会生成一些非常大的报告,这些报告需要很长时间才能执行。对于我们的主要 Web 客户端,我们开始生成报告,然后轮询{"result":"COMPLETED"}
响应中的类似内容。但是客户端只会轮询这么长时间——在没有看到COMPLETED
响应的 5 分钟后,它放弃并向用户显示错误消息。我想做的就是在场景中将此视为失败。
我目前已经实现了这样的东西......
exitBlockOnFail {
group("report polling") {
exec(_.set("completed", false))
.doWhileDuring(session => !session("completed").as[Boolean], timeout) {
exec(
http("polling action")
...
.check(jsonPath("$.result").transform(result => "COMPLETED".equals(result)).saveAs("completed")
)
}
// if we got here and didn't succeed then we timed out. This will mark the group as failed.
// failures on the polling action trigger an exit from the block
.doIf(session => !session("completed").as[Boolean])
{
exec(session => {
//logging a message to the console as there's no way to get this into the simulation.log
println(s"**** $description failed took more than: ${timeout.toString} (user: ${session("user").as[String]}****")
session.markAsFailed
})
}
}
}
这在 gatling 报告中显示为组失败,但没有错误消息,因为失败与请求无关。这使得破译报告变得困难,因为某些组失败也可能是由轮询请求失败引起的。
我刚刚开始使用的另一种方法是check.transform
在轮询请求中使用 a 在组执行开始时使用会话集中的时间戳来确定是否已超过超时。这意味着失败现在在请求中,并在报告中获得有意义的消息
group("report polling") {
exec(_.set("start", DateTime.now()))
.doWhileDuring(session => !session("result").as[String].equals("5"), timeout) {
exec( http("polling action")
...
.check(
responseTimeInMillis.transform((responseTime, session) => DateTime.now.getMillis - session("start")
.as[DateTime].getMillis).lte(timeout).name("Report generation timed out")
))
}
}}
但这感觉很混乱——轮询操作实际上并没有失败,并且围绕组行为的逻辑已经泄露到请求定义中。
理想情况下,我想.check
在组上有一个方法,我可以断言组持续时间小于超时,但我认为这是不可能的。
解决方案
推荐阅读
- python - 在python中仅在矩形的边缘上绘制没有尾巴的箱线图
- angular - 具有多个传递 docker-compose 变量的容器的通用 Docker 映像
- python - 尝试使用 keras 添加自定义图层时出现问题
- c# - 将 MessageTemplate 字符串传递给 Serilog 包装器
- pine-script - 通过代码 tradingview/pine 脚本隐藏图表、数量和信号标签上的交易
- date - 用于统计分析的日期转换
- google-apps-script - Google 脚本和 Google html 小部件之间的接口
- oracle - ORA-01008: 并非所有变量都绑定 - “并非所有变量都绑定”
- javascript - 使用适用于移动设备和桌面的 javascript 将文本复制到剪贴板
- java - 如何使用控制器初始化 LineChart 中的值/数据?