R Client for 'toxiproxy'
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.
The design is a bit weird because the entire point of this package is to make side effects happen to things that are probably meant to do side effects. So don't expect a composable pure functional interface.
toxiproxy is designed for use in tests; this package, being a fairly thin wrapper around the
toxiproxy client is 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 the
toxiproxy server to be running. You will need to know the host and port if you've changed them from the defaults.
knitr::opts_chunk$set(error = FALSE)
Create a redis forwarder:
tox <- toxiproxyr::toxiproxy_create("unreliable_redis", upstream = 6379)
We can connect a Redis client to 22222 and it will forward to 6379
redis <- redux::hiredis(port = tox$listen_port) redis$PING() system.time(redis$PING())
Then, simulate the server going down
(because of a design limitation in
redux the client will now need
Create a set of toxics with a 300ms delay and run a roundtrip over this slower connection (look at
Remove the proxy
For further documentation, see the package vignette.
Until the package is on CRAN, install from github
remotes::install_github("richfitz/toxiproxyr", upgrade = FALSE)
You will also need a toxiproxy server; this is a single executable that can be downloaded from the toxiproxy release page. Download the correct binary for your platform and make sure that it is executable.
Start the toxiproxy server; by default it will use port 8474 for communication.
If you want to use a different port, then start the toxiproxy server like
toxiproxy -port 8888
and the the envronment variable
TOXIPROXY_PORT to this value. For example, within R
Sys.setenv(TOXIPROXY_PORT = 8888)
(alternatively all commands have a
toxiproxy_port argument that you can specify if you would rather)
Be aware that running tests will delete all your proxies (using
toxiproxy_clear fairly liberally). If you use toxiproxy for other applications it will generally be good to start a separate server.
If you run
make toxiproxy_start, a new server will start on port 9999. You can stop if later with
MIT + file LICENSE © Rich FitzJohn.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.