knitr::opts_chunk$set(error = FALSE)
toxiproxy is an unfathful proxy; it forwards data to and from a service with various "toxic" attributes. The data might be delayed (simulating a slow network connection), dropping the connection, restricting total bandwidth, and other bits of pollution. These can be added together.
toxiproxy is designed for use in tests; this package, as a client for
toxiproxy the same. It's primary uses will be for use in tests for packages that do things over the network. For example:
I do not expect that this package will be of interest to the vast majority of R users, and I don't expect it to be useful within core package code.
toxiproxyr requires a
toxiproxy server to be running. If you already have one configured, then you can set the environment variable
TOXIPROXY_ADDR to point at the server and
toxiproxyr will use this server when you run
cl <- toxiproxyr::toxiproxy_client()
toxiproxyr can install a server for you - this is the interface designed for testing environments like travis and appveyor. In that case, set the environment variable
TOXIPROXYR_SERVER_BIN_PATH to the directory to install
toxiproxy into. Then, in the tests run
srv <- toxiproxyr::toxiproxy_server()
which will give you a brand new toxiproxy server
srv which will be deleted once the
srv object goes out of scope (this is designed for use within
test_that blocks. Then create a client:
cl <- srv$client()
To interact with the server, through the client, use the methods:
For example, we might create an unreliable redis proxy:
proxy <- cl$create("unreliable_redis", upstream = 6379)
listen port was given, this runs on a random port:
Connect a redis client to our new proxy
redis <- redux::hiredis(port = proxy$listen_port) redis$PING()
We can simulate a slow connection by adding latency:
system.time(redis$PING())[["elapsed"]] proxy$add(toxiproxyr::latency(300)) system.time(redis$PING())[["elapsed"]]
or simulate server or network failure by disabling the proxy entirely:
Until the package is on CRAN, install from github
remotes::install_github("richfitz/toxiproxyr", upgrade = FALSE)
MIT + file LICENSE © Rich FitzJohn.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.