Skip to content
Toxiproxy.Net is a .Net client for Shopify's Toxiproxy. Toxiproxy is a proxy to test your system by simulating network failure.
C#
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget
Toxiproxy.Net.Tests
Toxiproxy.Net
compiled/Win64
.gitignore
LICENSE
Toxiproxy.Net.nuspec
Toxiproxy.Net.sln Added in some anti-regression tests plus a compiled version to test a… Mar 25, 2015
appveyor.yml
readme.md

readme.md

Toxiproxy.Net

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

Build status

Master branch

Build status

Test Coverage

Coverage Status

Getting started

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

Usage

The unit tests give a good overview of how to fully use the api. Here are some examples to get started -

Start Toxiproxy

_proxyProcess = new Process()
    {
        StartInfo = new ProcessStartInfo(@".\packages\Toxiproxy.Net\compiled\Win64\toxiproxy-server-2.1.2-windows-amd64.exe")
    };
_proxyProcess.Start();

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 timeoutProxy = new TimeoutToxic();
timeoutProxy.Attributes.Timeout = 100;
timeoutProxy.Toxicity = 1.0;

proxy.Add(timeoutProxy);
proxy.Update();

Return a list of all proxies

var connection = new Connection();
var client = connection.Client();

client.All();

Reset all proxies 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 proxy = connection.Client().FindProxy("ms_sql");
        var latency = (LatencyToxic)proxy.GetToxicByName("Latency");


        // set a latency of 1 second 
        latency.Attributes.Latency = 1000;

        // save it
        proxy.Update();

        // do your test....

    }

Thanks

soneyworld Federico Orlandini vromantp mgkeen

You can’t perform that action at this time.