latencyΒΆ

Simulating service latency during the development phase of a service is good practice, as it forces developers to write code that acts gracefully and resiliently in the event of unexpected latency during network io.

To add latency to services, simply add the FQDN, delay in milliseconds, and optional HTTP method in an array of tuples for the delays parameter.

# latency.py

from hoverpy import capture
import requests

delays = [("time.jsontest.com", 3000, "GET"), ("echo.jsontest.com", 1000)]

@capture("delays.db", recordMode="once", delays=delays)
def simulate_network_latency():
    print(requests.get("http://time.jsontest.com").text)
    print(requests.get("http://echo.jsontest.com/a/b").text)

simulate_network_latency()
$ python examples/latency/latency.py

The latency is added when querying these services. If the HTTP method is omitted in the tupes, then the delay applies to all methods.