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 authored and raman-m committed May 20, 2023
1 parent bc25f4e commit 91eed16
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 @@ -26,9 +26,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 @@ -44,18 +44,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 @@ -85,18 +85,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 @@ -127,18 +126,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 91eed16

Please sign in to comment.