问题
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