Skip to content

Commit

Permalink
Fixing an issue where only setting timeout value in QoS would result …
Browse files Browse the repository at this point in the history
…in a exception getting thrown. Issue #908
  • Loading branch information
DanHarltey committed Jul 1, 2020
1 parent c3a0cf1 commit 540479f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
15 changes: 12 additions & 3 deletions src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
{
try
{
return await Policy
.WrapAsync(_qoSProvider.CircuitBreaker.Policies)
.ExecuteAsync(() => base.SendAsync(request, cancellationToken));
IAsyncPolicy policy;

if (_qoSProvider.CircuitBreaker.Policies.Length == 1)
{
policy = _qoSProvider.CircuitBreaker.Policies[0];
}
else
{
policy = Policy.WrapAsync(_qoSProvider.CircuitBreaker.Policies);
}

return await policy.ExecuteAsync(() => base.SendAsync(request, cancellationToken));
}
catch (BrokenCircuitException ex)
{
Expand Down
27 changes: 13 additions & 14 deletions test/Ocelot.AcceptanceTests/PollyQoSTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ public void should_not_timeout()
{
Host = "localhost",
Port = port,
}
},
},
DownstreamScheme = "http",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Post" },
QoSOptions = new FileQoSOptions
{
TimeoutValue = 1000,
ExceptionsAllowedBeforeBreaking = 10
}
}
}
ExceptionsAllowedBeforeBreaking = 10,
},
},
},
};

this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, string.Empty, 10))
Expand Down Expand Up @@ -81,18 +81,17 @@ public void should_timeout()
{
Host = "localhost",
Port = port,
}
},
},
DownstreamScheme = "http",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Post" },
QoSOptions = new FileQoSOptions
{
TimeoutValue = 10,
ExceptionsAllowedBeforeBreaking = 10
}
}
}
},
},
},
};

this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 201, string.Empty, 1000))
Expand Down Expand Up @@ -123,18 +122,18 @@ public void should_open_circuit_breaker_then_close()
{
Host = "localhost",
Port = port,
}
},
},
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Get" },
QoSOptions = new FileQoSOptions
{
ExceptionsAllowedBeforeBreaking = 1,
TimeoutValue = 500,
DurationOfBreak = 1000
DurationOfBreak = 1000,
},
}
}
},
},
};

this.Given(x => x.GivenThereIsAPossiblyBrokenServiceRunningOn($"http://localhost:{port}", "Hello from Laura"))
Expand Down

0 comments on commit 540479f

Please sign in to comment.