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      "globalActions": {
 2         "delays": [
 3            {
 4               "urlPattern": "echo\\.jsontest\\.com\\/a\\/b",
 5               "httpMethod": "",
 6               "delay": 2000
 7            },
 8            {
 9               "urlPattern": "echo\\.jsontest\\.com\\/b\\/c",
10               "httpMethod": "",
11               "delay": 2000
12            },
13            {
14               "urlPattern": "echo\\.jsontest\\.com\\/c\\/d",
15               "httpMethod": "",
16               "delay": 3000
17            }
18         ],
19         "delaysLogNormal": []

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).