Every response saves the time it took to call the downstream service in the
_proxyResponseTime
field. You can tell mountebank to automatically
translate that into a wait behavior,
which will add the same latency to the saved response. This is a useful technique
during performance testing, where you want to virtualize downstream services but
still want realistic latencies.
POST /imposters HTTP/1.1
Host: localhost:<%= port %>
Content-Type: application/json
{
"port": 6001,
"protocol": "http"
}
Let's create the following proxy configuration:
POST /imposters HTTP/1.1
Host: localhost:<%= port %>
Content-Type: application/json
{
"port": 6000,
"protocol": "http",
"stubs": [{
"responses": [{
"proxy": {
"to": "http://origin-server.com ",
"addWaitBehavior": true
}
}]
}]}
Next we'll send a request to our proxy imposter to create a new saved response:
GET / HTTP/1.1
Host: origin-server.com
If you look at the imposter configuration, you'll notice the new wait
behavior. The value will be the same as the _proxyResponseTime
field, which
means that the saved response will add the same latency as the real service.
GET /imposters/6000 HTTP/1.1
Host: localhost:<%= port %>
{
"stubs": [
{
"predicates": [],
"responses": [{
"is": {
"statusCode": 200,
...
"_proxyResponseTime": 219
},
"behaviors": [
{
"wait": 219
}
]
}]
},
{
"responses": [{
"proxy": {
"to": "http://origin-server.com ",
"addWaitBehavior": true
}
}]
}
]}
DELETE /imposters/6001 HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json
DELETE /imposters/6000 HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json