Skip to content

Instantly share code, notes, and snippets.

View josephwoodward's full-sized avatar

Joseph Woodward josephwoodward

View GitHub Profile
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)
}
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
package main
import (
toxiproxy "github.com/Shopify/toxiproxy/v2/client"
"os"
"testing"
)
var client *toxiproxy.Client
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == HttpStatusCode.ServiceUnavailable)
.RetryAsync(3);
}
[Fact]
public async Task ShouldRetryTransientErrors()
public static IHttpClientBuilder AddPolicyHandler(this IHttpClientBuilder builder, IAsyncPolicy<HttpResponseMessage> policy)
{
...
builder.AddHttpMessageHandler(() => new PolicyHttpMessageHandler(policy));
return builder;
}
var collection = new ServiceCollection()
.AddHttpClient("myNamedClient")
.AddPolicyHandler(GetRetryPolicy()); // here
...
[IgnoreOnAppVeyorLinuxFact]
public void ShouldlyApi()
{
...
}
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;
[Fact(Skip = "Doesn't work at the moment")]
public void ClassScenarioShouldFail()
{
...
}
@josephwoodward
josephwoodward / skip1.cs
Created July 21, 2020 14:36
xunitskip1.cs
#if IS_LINUX
[Fact]
public void ShouldlyApi()
{
...
}
#endif