How can I test async callbacks in JMeter?

时间秒杀一切 提交于 2020-07-19 07:05:46

问题


I am using WebHooks in my API. So, once a request is processed our REST Service will POST a response back to the callback URL sent in the request.

Client             Server
  |(request)         |
  |----------------->|     
  |<-----------------|     ||
  |        (response)|     ||
  |                  |    _||_ Time
  |        (callback)|    \  /
  |<-----------------|     \/
  |----------------->|
  |(response)        |
  |                  |

How can this be stress tested with JMeter?


回答1:


It depends on WebHook implementation, if it is a matter of polling - you can just use While Controller to wait for callback in loops. The whole duration of the sequence can be measured using i.e. Transaction Controller

If the callback comes a a Server-Sent Event you can use i.e. JAX RS API which provides SseEventSource class which can be used for waiting for server-side events either in JSR223 Sampler or in Java Request sampler like described in Stress/Load-Testing of Asynchronous HTTP/REST Services with JMeter article




回答2:


You have to listen to incomming connections of certain port. Make sure you machine can be connected from outside. In JMeter you can use JSR223 Sampler and following Groovy script

def server = new ServerSocket(8080)
while (true) {
    server.accept { socket ->
        socket.withStreams { input, output ->
            def reader = input.newReader()
            log.info('Received request:')
            while ((line = reader.readLine()) != null) {
                log.info(line)
            }
        }
    }
}


来源:https://stackoverflow.com/questions/48025063/how-can-i-test-async-callbacks-in-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!