Toxiproxy.Net is a .Net client for Shopify's Toxiproxy REST/JSON Api. Toxiproxy is a proxy to test your system by simulating network failure.
Project
Master branch
Test Coverage
To install via the nuget package console
Install-Package Toxiproxy.Net
A copy of toxiproxy compiled for windows is in the compiled folder. Linux, Darwin and Windows builds are available from the official release site
The unit tests give a good overview of how to fully use the api. Here are some examples to get started -
Set up a proxy
var connection = new Connection();
var client = connection.Client();
//proxy all traffic from 127.0.0.1:44399 to https://google.com
var localToGoogleProxy = new Proxy() {
Name = "localToGoogle",
Enabled = true,
Listen = "127.0.0.1:44399",
Upstream = "google.com:443"
};
client.Add(localToGoogleProxy);
Disable a proxy
var connection = new Connection();
var client = connection.Client();
var proxy = client.FindProxy("localToGoogle");
proxy.Enabled = false;
proxy.Update();
Timeout a proxy
var connection = new Connection();
var client = connection.Client();
var proxy = client.FindProxy("localToGoogle");
var timeout = proxy.UpStreams().TimeoutToxic;
timeout.Enabled = true;
timeout.Update();
Return a list of all proxies
var connection = new Connection();
var client = connection.Client();
client.All();
Reset all proxes to a good state automatically
// assuming the proxy is running with its default settings e.g. localhost:8474
// and there is a connection defined with the name "ms_sql"
// create a connection to toxiproxy that will call reset on disposal
// this resets the state of all the toxics and re-enables all of the proxies
using (var connection = new Connection(true))
{
// find the upstream latency toxic
var latency = connection.Client().FindProxy("ms_sql").UpStreams().LatencyToxic;
// set a latency of 1 second
latency.Latency = 1000;
// save it
latency.Update();
// do your test....
}