toxiproxyr

Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Linux Build Status Windows Build status codecov.io

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.

Target audience and use cases

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.

Interface

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)
toxiproxyr::toxiproxy_clear()

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

tox$with_down(redis$PING())

(because of a design limitation in redux the client will now need reconnecting)

redis$reconnect()

Create a set of toxics with a 300ms delay and run a roundtrip over this slower connection (look at elapsed):

system.time(tox$with(toxiproxyr::latency(300),
                     redis$PING()))

Remove the proxy

tox$destroy()

For further documentation, see the package vignette.

Installation

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)

Running tests

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 make toxiproxy_stop.

License

MIT + file LICENSE © Rich FitzJohn.



richfitz/toxiproxyr documentation built on May 25, 2017, 3:10 a.m.