Applying different delays based on URIΒΆ
Now let’s apply different delays based on location. Run the following to create and export a simulation.
hoverctl start
hoverctl mode capture
curl --proxy localhost:8500 http://echo.jsontest.com/a/b
curl --proxy localhost:8500 http://echo.jsontest.com/b/c
curl --proxy localhost:8500 http://echo.jsontest.com/c/d
hoverctl export simulation.json
hoverctl stop
Edit the simulation.json
file so that the "globalActions"
property looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | "globalActions": {
"delays": [
{
"urlPattern": "echo\\.jsontest\\.com\\/a\\/b",
"httpMethod": "",
"delay": 2000
},
{
"urlPattern": "echo\\.jsontest\\.com\\/b\\/c",
"httpMethod": "",
"delay": 2000
},
{
"urlPattern": "echo\\.jsontest\\.com\\/c\\/d",
"httpMethod": "",
"delay": 3000
}
]
}
|
Now run the following to import the edited simulation.json
file and run the simulation:
hoverctl start
hoverctl import simulation.json
hoverctl mode simulate
curl --proxy localhost:8500 http://echo.jsontest.com/a/b
curl --proxy localhost:8500 http://echo.jsontest.com/b/c
curl --proxy localhost:8500 http://echo.jsontest.com/c/d
hoverctl stop
You should notice a 2 second delay on responses from echo.jsontest.com/a/b
and echo.jsontest.com/b/c
, and a 3 second delay on the response from echo.jsontest.com/c/d
.
Note
When you use Hoverfly as a webserver, you should replace or remove any original host pattern in the urlPattern
filter, because the endpoint URL is based on Hoverfly webserver address (eg. http://localhost:8888
).