public async Task Add_Toxiproxy_Proxy_Success() { // add a proxy var proxy = new Proxy() { Name = "AddToxiproxyProxySuccess", Listen = "127.0.0.1:8899", Upstream = "postman-echo.com:80", Enabled = true }; // get the created proxy var createdProxy = await _toxiproxyClient.AddProxyAsync(proxy); // clean up after our test by removing the proxy await _toxiproxyClient.DeleteProxyAsync(createdProxy.Name); // result should not be null Assert.IsNotNull(createdProxy); }
public async Task Get_Echo_Success_Test_Toxiproxy_Endpoint() { // create a new toxiproxy proxy var toxiproxyClient = new ToxiproxyClient(_httpClient, _toxiproxyServerUri); // add the toxiproxy proxy we will use for testing var proxy = await toxiproxyClient.AddProxyAsync(new Proxy() { Name = "GetEchoSuccessTestToxiproxyEndpoint", Listen = "127.0.0.1:8888", Upstream = "postman-echo.com:80", Enabled = true }); PostmanEcho result = null; try { // set the uri to test as the toxiproxy proxy upstream endpoint _chaosApiClient.ApiUri = new Uri($"http://{proxy.Listen}/get?foo1=bar1&foo2=bar2"); // create a new instance of Module to test _module = new Module(_chaosApiClient, new Mock <ILogger <Module> >().Object); // test the GetDataAsync method result = await _module.GetDataAsync(); } catch (Exception exception) { // TODO: add logging throw; } finally { // clean up the proxy we created for testing await toxiproxyClient.DeleteProxyAsync(proxy.Name); } // result should not be null Assert.IsNotNull(result); }
public async Task Get_Echo_Latency_Test_Toxiproxy_Endpoint() { // var to specify 5 seconds of latency to introduce into the API call var latency = 5000; // create a new ToxiproxyClient instance var toxiproxyClient = new ToxiproxyClient(_httpClient, _toxiproxyServerUri); // add the toxiproxy proxy we will use for testing var proxy = await toxiproxyClient.AddProxyAsync(new Proxy() { Name = "GetEchoLatencyTestToxiproxyEndpoint", Listen = "127.0.0.1:8888", Upstream = "postman-echo.com:80", Enabled = true }); // create a new latency toxic instance var newToxic = new LatencyToxic() { Name = "GetEchoLatencyTestToxic", Type = LatencyToxic.ToxicType, Stream = "upstream", // TODO: need to move to enum Toxicity = 1 }; newToxic.Attributes.Latency = latency; newToxic.Attributes.Jitter = 0; // add the toxic to the toxiproxy proxy var toxic = await toxiproxyClient.AddToxicAsync <LatencyToxic>(newToxic, proxy.Name); PostmanEcho result = null; var stopWatch = new Stopwatch(); try { // set the uri to test as the toxiproxy proxy upstream endpoint _chaosApiClient.ApiUri = new Uri($"http://{proxy.Listen}/get?foo1=bar1&foo2=bar2"); // create a new instance of Module to test _module = new Module(_chaosApiClient, new Mock <ILogger <Module> >().Object); // test the GetDataAsync method and track the execution time stopWatch.Start(); result = await _module.GetDataAsync(); stopWatch.Stop(); } catch (Exception exception) { // TODO: add logging throw; } finally { // clean up the proxy we created for testing await toxiproxyClient.DeleteProxyAsync(proxy.Name); } // result should not be null Assert.IsNotNull(result); // API call should have taken longer to execute than the latency injected into toxiproxy Assert.IsTrue(stopWatch.ElapsedMilliseconds > latency); }