This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestSlowConnection(t *testing.T) { | |
// Arrange | |
// Use the client to get our proxy configured on test setup | |
proxy, err := client.Proxy("upstream_api") | |
if err != nil { | |
t.Fatalf("fetching proxy 'upstream_api': %v", err) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestSlowConnection(t *testing.T) { | |
// Arrange | |
// Use the client to get our proxy configured on test setup | |
proxy, err := client.Proxy("upstream_api") | |
if err != nil { | |
t.Fatalf("fetching proxy 'upstream_api': %v", err) | |
} | |
// Add a 'toxic' to introduce 3 seconds latency into the upstream request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
toxiproxy "github.com/Shopify/toxiproxy/v2/client" | |
"os" | |
"testing" | |
) | |
var client *toxiproxy.Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy() | |
{ | |
return HttpPolicyExtensions | |
.HandleTransientHttpError() | |
.OrResult(msg => msg.StatusCode == HttpStatusCode.ServiceUnavailable) | |
.RetryAsync(3); | |
} | |
[Fact] | |
public async Task ShouldRetryTransientErrors() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IHttpClientBuilder AddPolicyHandler(this IHttpClientBuilder builder, IAsyncPolicy<HttpResponseMessage> policy) | |
{ | |
... | |
builder.AddHttpMessageHandler(() => new PolicyHttpMessageHandler(policy)); | |
return builder; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var collection = new ServiceCollection() | |
.AddHttpClient("myNamedClient") | |
.AddPolicyHandler(GetRetryPolicy()); // here | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[IgnoreOnAppVeyorLinuxFact] | |
public void ShouldlyApi() | |
{ | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class IgnoreOnAppVeyorLinuxFact : FactAttribute | |
{ | |
public IgnoreOnAppVeyorLinuxFact() { | |
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && IsAppVeyor()) { | |
Skip = "Ignore on Linux when run via AppVeyor"; | |
} | |
} | |
private static bool IsAppVeyor() | |
=> Environment.GetEnvironmentVariable("APPVEYOR") != null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact(Skip = "Doesn't work at the moment")] | |
public void ClassScenarioShouldFail() | |
{ | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if IS_LINUX | |
[Fact] | |
public void ShouldlyApi() | |
{ | |
... | |
} | |
#endif |
NewerOlder