推送消息,然后轮询结果(Push a message and then Poll for a result)

编程入门 行业动态 更新时间:2024-10-27 22:29:04
推送消息,然后轮询结果(Push a message and then Poll for a result)

我们有两个服务,一个接收消息,另一个告诉我们消息何时被处理。 我正试图在一次加速测试中加以说明。 这是我迄今为止的,但我最后一点挣扎..

scenario("push message and poll for result") .feed(feeder) .group("push and check: group") { exec(http("push") .put("/create") .check(status.is(200)) ) .asLongAs(session => !session.contains("messageProcessed")) { exec(http("poll") .get("/poll") .check(status.is(200), jsonPath("$.results[0].resultCount").saveAs("resultCount")) } }

我的问题是resultCount最初将为零,所以我想保持轮询,直到它变为!= 0。当发生这种情况时,我想我可以将“messageProcessed”设置为某个值,然后它将退出循环。

有没有办法做到这一点? 谢谢你的帮助。

We have two services, one which receives a message and a second which tells us when the message has been processed. I'm trying to cover this in a gatling test. Here's what I have so far but I'm struggling with the last bit..

scenario("push message and poll for result") .feed(feeder) .group("push and check: group") { exec(http("push") .put("/create") .check(status.is(200)) ) .asLongAs(session => !session.contains("messageProcessed")) { exec(http("poll") .get("/poll") .check(status.is(200), jsonPath("$.results[0].resultCount").saveAs("resultCount")) } }

My problem is resultCount will initially be zero so I want to keep polling until it becomes != 0. When this happens I thought I could set "messageProcessed" to something and then it would drop out of the loop.

Is there a way to do this? Thanks for your help.

最满意答案

这是我最终使用的解决方案

.asLongAs(session => getResultCount(session) == 0) {

并添加了这个方法:

def getResultCount(session: Session): Int = { session("resultCount").asOption[String].map(_.toInt).getOrElse(0) }

this was the solution I used in the end

.asLongAs(session => getResultCount(session) == 0) {

and added this method:

def getResultCount(session: Session): Int = { session("resultCount").asOption[String].map(_.toInt).getOrElse(0) }

更多推荐

本文发布于:2023-08-07 23:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   Push   message   Poll   result

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!