diff --git a/docs/features/loadbalancer.rst b/docs/features/loadbalancer.rst index 1fd54d17..02905094 100644 --- a/docs/features/loadbalancer.rst +++ b/docs/features/loadbalancer.rst @@ -214,6 +214,6 @@ There are numerous extension methods to add a custom load balancer and the inter Func loadBalancerFactoryFunc) where T : ILoadBalancer; -When you enable custom load balancers Ocelot looks up your load balancer by its class name when it decides if it should do load balancing. If it finds a match it will load balance your request. If Ocelot cannot match the load balancer type in your configuration with the name of registered load balancer class then you will receive a HTTP 500 internal server error. +When you enable custom load balancers Ocelot looks up your load balancer by its class name when it decides if it should do load balancing. If it finds a match it will use your load balaner to load balance. If Ocelot cannot match the load balancer type in your configuration with the name of registered load balancer class then you will receive a HTTP 500 internal server error. If your load balancer factory throw an exception when Ocelot calls it you will receive a HTTP 500 internal server error. Remember if you specify no load balancer in your config Ocelot will not try and load balance. \ No newline at end of file diff --git a/src/Ocelot/Errors/OcelotErrorCode.cs b/src/Ocelot/Errors/OcelotErrorCode.cs index 92c125a7..2ca44e70 100644 --- a/src/Ocelot/Errors/OcelotErrorCode.cs +++ b/src/Ocelot/Errors/OcelotErrorCode.cs @@ -42,5 +42,6 @@ RequestCanceled = 37, ConnectionToDownstreamServiceError = 38, CouldNotFindLoadBalancerCreator = 39, + ErrorInvokingLoadBalancerCreator = 40, } } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessionsCreator.cs b/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessionsCreator.cs index e78b1884..2f17882e 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessionsCreator.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/CookieStickySessionsCreator.cs @@ -4,15 +4,16 @@ using Ocelot.Configuration; using Ocelot.Infrastructure; using Ocelot.ServiceDiscovery.Providers; + using Ocelot.Responses; public class CookieStickySessionsCreator : ILoadBalancerCreator { - public ILoadBalancer Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) + public Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) { var loadBalancer = new RoundRobin(async () => await serviceProvider.Get()); var bus = new InMemoryBus(); - return new CookieStickySessions(loadBalancer, reRoute.LoadBalancerOptions.Key, - reRoute.LoadBalancerOptions.ExpiryInMs, bus); + return new OkResponse(new CookieStickySessions(loadBalancer, reRoute.LoadBalancerOptions.Key, + reRoute.LoadBalancerOptions.ExpiryInMs, bus)); } public string Type => nameof(CookieStickySessions); diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/DelegateInvokingLoadBalancerCreator.cs b/src/Ocelot/LoadBalancer/LoadBalancers/DelegateInvokingLoadBalancerCreator.cs index 535550dc..3a055427 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/DelegateInvokingLoadBalancerCreator.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/DelegateInvokingLoadBalancerCreator.cs @@ -3,6 +3,7 @@ using System; using Ocelot.Configuration; using Ocelot.ServiceDiscovery.Providers; + using Ocelot.Responses; public class DelegateInvokingLoadBalancerCreator : ILoadBalancerCreator where T : ILoadBalancer @@ -15,9 +16,17 @@ _creatorFunc = creatorFunc; } - public ILoadBalancer Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) + public Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) { - return _creatorFunc(reRoute, serviceProvider); + try + { + return new OkResponse(_creatorFunc(reRoute, serviceProvider)); + + } + catch (Exception e) + { + return new ErrorResponse(new ErrorInvokingLoadBalancerCreator(e)); + } } public string Type => typeof(T).Name; diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/ErrorInvokingLoadBalancerCreator.cs b/src/Ocelot/LoadBalancer/LoadBalancers/ErrorInvokingLoadBalancerCreator.cs new file mode 100644 index 00000000..022814c5 --- /dev/null +++ b/src/Ocelot/LoadBalancer/LoadBalancers/ErrorInvokingLoadBalancerCreator.cs @@ -0,0 +1,12 @@ +namespace Ocelot.LoadBalancer.LoadBalancers +{ + using System; + using Errors; + + public class ErrorInvokingLoadBalancerCreator : Error + { + public ErrorInvokingLoadBalancerCreator(Exception e) : base($"Error when invoking user provided load balancer creator function, Message: {e.Message}, StackTrace: {e.StackTrace}", OcelotErrorCode.ErrorInvokingLoadBalancerCreator) + { + } + } +} diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerCreator.cs b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerCreator.cs index 4831e62f..c2df1dae 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerCreator.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/ILoadBalancerCreator.cs @@ -1,11 +1,12 @@ -using Ocelot.Configuration; -using Ocelot.ServiceDiscovery.Providers; - -namespace Ocelot.LoadBalancer.LoadBalancers +namespace Ocelot.LoadBalancer.LoadBalancers { + using Ocelot.Responses; + using Ocelot.Configuration; + using Ocelot.ServiceDiscovery.Providers; + public interface ILoadBalancerCreator { - ILoadBalancer Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider); + Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider); string Type { get; } } } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnectionCreator.cs b/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnectionCreator.cs index e9e9c561..509a04a1 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnectionCreator.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/LeastConnectionCreator.cs @@ -2,12 +2,13 @@ { using Ocelot.Configuration; using Ocelot.ServiceDiscovery.Providers; + using Ocelot.Responses; public class LeastConnectionCreator : ILoadBalancerCreator { - public ILoadBalancer Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) + public Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) { - return new LeastConnection(async () => await serviceProvider.Get(), reRoute.ServiceName); + return new OkResponse(new LeastConnection(async () => await serviceProvider.Get(), reRoute.ServiceName)); } public string Type => nameof(LeastConnection); diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs b/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs index 93cd0adb..31b6f74d 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/LoadBalancerFactory.cs @@ -35,8 +35,14 @@ return new ErrorResponse(new CouldNotFindLoadBalancerCreator($"Could not find load balancer creator for Type: {requestedType}, please check your config specified the correct load balancer and that you have registered a class with the same name.")); } - var createdLoadBalancer = applicableCreator.Create(reRoute, serviceProvider); - return new OkResponse(createdLoadBalancer); + var createdLoadBalancerResponse = applicableCreator.Create(reRoute, serviceProvider); + + if (createdLoadBalancerResponse.IsError) + { + return new ErrorResponse(createdLoadBalancerResponse.Errors); + } + + return new OkResponse(createdLoadBalancerResponse.Data); } } } diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancerCreator.cs b/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancerCreator.cs index fc1de3fd..ea2fdd7a 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancerCreator.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancerCreator.cs @@ -2,12 +2,13 @@ { using Ocelot.Configuration; using Ocelot.ServiceDiscovery.Providers; + using Ocelot.Responses; public class NoLoadBalancerCreator : ILoadBalancerCreator { - public ILoadBalancer Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) + public Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) { - return new NoLoadBalancer(async () => await serviceProvider.Get()); + return new OkResponse(new NoLoadBalancer(async () => await serviceProvider.Get())); } public string Type => nameof(NoLoadBalancer); diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobinCreator.cs b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobinCreator.cs index 8981074d..fd698133 100644 --- a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobinCreator.cs +++ b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobinCreator.cs @@ -2,12 +2,13 @@ { using Ocelot.Configuration; using Ocelot.ServiceDiscovery.Providers; - + using Ocelot.Responses; + public class RoundRobinCreator : ILoadBalancerCreator { - public ILoadBalancer Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) + public Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) { - return new RoundRobin(async () => await serviceProvider.Get()); + return new OkResponse(new RoundRobin(async () => await serviceProvider.Get())); } public string Type => nameof(RoundRobin); diff --git a/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs b/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs index 6bb85ba9..841f788d 100644 --- a/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs +++ b/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs @@ -46,7 +46,8 @@ namespace Ocelot.Responder } if (errors.Any(e => e.Code == OcelotErrorCode.UnableToCompleteRequestError - || e.Code == OcelotErrorCode.CouldNotFindLoadBalancerCreator)) + || e.Code == OcelotErrorCode.CouldNotFindLoadBalancerCreator + || e.Code == OcelotErrorCode.ErrorInvokingLoadBalancerCreator)) { return 500; } diff --git a/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsCreatorTests.cs b/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsCreatorTests.cs index bf004010..ece2286e 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/CookieStickySessionsCreatorTests.cs @@ -1,20 +1,21 @@ -using Moq; -using Ocelot.Configuration; -using Ocelot.Configuration.Builder; -using Ocelot.LoadBalancer.LoadBalancers; -using Ocelot.ServiceDiscovery.Providers; -using Shouldly; -using TestStack.BDDfy; -using Xunit; - -namespace Ocelot.UnitTests.LoadBalancer +namespace Ocelot.UnitTests.LoadBalancer { + using Moq; + using Ocelot.Configuration; + using Ocelot.Configuration.Builder; + using Ocelot.LoadBalancer.LoadBalancers; + using Ocelot.ServiceDiscovery.Providers; + using Ocelot.Responses; + using Shouldly; + using TestStack.BDDfy; + using Xunit; + public class CookieStickySessionsCreatorTests { private readonly CookieStickySessionsCreator _creator; private readonly Mock _serviceProvider; private DownstreamReRoute _reRoute; - private ILoadBalancer _loadBalancer; + private Response _loadBalancer; private string _typeName; public CookieStickySessionsCreatorTests() @@ -62,7 +63,7 @@ namespace Ocelot.UnitTests.LoadBalancer private void ThenTheLoadBalancerIsReturned() where T : ILoadBalancer { - _loadBalancer.ShouldBeOfType(); + _loadBalancer.Data.ShouldBeOfType(); } private void ThenTheLoadBalancerTypeIs(string type) diff --git a/test/Ocelot.UnitTests/LoadBalancer/DelegateInvokingLoadBalancerCreatorTests.cs b/test/Ocelot.UnitTests/LoadBalancer/DelegateInvokingLoadBalancerCreatorTests.cs index 2be4ee62..d46be02b 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/DelegateInvokingLoadBalancerCreatorTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/DelegateInvokingLoadBalancerCreatorTests.cs @@ -16,11 +16,11 @@ namespace Ocelot.UnitTests.LoadBalancer { public class DelegateInvokingLoadBalancerCreatorTests { - private readonly DelegateInvokingLoadBalancerCreator _creator; - private readonly Func _creatorFunc; + private DelegateInvokingLoadBalancerCreator _creator; + private Func _creatorFunc; private readonly Mock _serviceProvider; private DownstreamReRoute _reRoute; - private ILoadBalancer _loadBalancer; + private Response _loadBalancer; private string _typeName; public DelegateInvokingLoadBalancerCreatorTests() @@ -51,6 +51,31 @@ namespace Ocelot.UnitTests.LoadBalancer .BDDfy(); } + [Fact] + public void should_return_error() + { + var reRoute = new DownstreamReRouteBuilder() + .Build(); + + this.Given(x => x.GivenAReRoute(reRoute)) + .And(x => x.GivenTheCreatorFuncThrows()) + .When(x => x.WhenIGetTheLoadBalancer()) + .Then(x => x.ThenAnErrorIsReturned()) + .BDDfy(); + } + + private void GivenTheCreatorFuncThrows() + { + _creatorFunc = (reRoute, serviceDiscoveryProvider) => throw new Exception(); + + _creator = new DelegateInvokingLoadBalancerCreator(_creatorFunc); + } + + private void ThenAnErrorIsReturned() + { + _loadBalancer.IsError.ShouldBeTrue(); + } + private void GivenAReRoute(DownstreamReRoute reRoute) { _reRoute = reRoute; @@ -69,7 +94,7 @@ namespace Ocelot.UnitTests.LoadBalancer private void ThenTheLoadBalancerIsReturned() where T : ILoadBalancer { - _loadBalancer.ShouldBeOfType(); + _loadBalancer.Data.ShouldBeOfType(); } private void ThenTheLoadBalancerTypeIs(string type) diff --git a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionCreatorTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionCreatorTests.cs index 37d678cd..326ecbd7 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionCreatorTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionCreatorTests.cs @@ -1,20 +1,21 @@ -using Moq; -using Ocelot.Configuration; -using Ocelot.Configuration.Builder; -using Ocelot.LoadBalancer.LoadBalancers; -using Ocelot.ServiceDiscovery.Providers; -using Shouldly; -using TestStack.BDDfy; -using Xunit; - -namespace Ocelot.UnitTests.LoadBalancer +namespace Ocelot.UnitTests.LoadBalancer { + using Moq; + using Ocelot.Configuration; + using Ocelot.Configuration.Builder; + using Ocelot.LoadBalancer.LoadBalancers; + using Ocelot.Responses; + using Ocelot.ServiceDiscovery.Providers; + using Shouldly; + using TestStack.BDDfy; + using Xunit; + public class LeastConnectionCreatorTests { private readonly LeastConnectionCreator _creator; private readonly Mock _serviceProvider; private DownstreamReRoute _reRoute; - private ILoadBalancer _loadBalancer; + private Response _loadBalancer; private string _typeName; public LeastConnectionCreatorTests() @@ -62,7 +63,7 @@ namespace Ocelot.UnitTests.LoadBalancer private void ThenTheLoadBalancerIsReturned() where T : ILoadBalancer { - _loadBalancer.ShouldBeOfType(); + _loadBalancer.Data.ShouldBeOfType(); } private void ThenTheLoadBalancerTypeIs(string type) diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs index a08a808f..b70f8371 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerFactoryTests.cs @@ -16,6 +16,8 @@ using Xunit; namespace Ocelot.UnitTests.LoadBalancer { + using System; + public class LoadBalancerFactoryTests { private DownstreamReRoute _reRoute; @@ -35,6 +37,7 @@ namespace Ocelot.UnitTests.LoadBalancer new FakeLoadBalancerCreator(), new FakeLoadBalancerCreator(), new FakeLoadBalancerCreator(nameof(NoLoadBalancer)), + new BrokenLoadBalancerCreator(), }; _factory = new LoadBalancerFactory(_serviceProviderFactory.Object, _loadBalancerCreators); } @@ -87,6 +90,22 @@ namespace Ocelot.UnitTests.LoadBalancer .BDDfy(); } + [Fact] + public void should_return_error_response_if_creator_errors() + { + var reRoute = new DownstreamReRouteBuilder() + .WithLoadBalancerOptions(new LoadBalancerOptions("BrokenLoadBalancer", "", 0)) + .WithUpstreamHttpMethod(new List { "Get" }) + .Build(); + + this.Given(x => x.GivenAReRoute(reRoute)) + .And(x => GivenAServiceProviderConfig(new ServiceProviderConfigurationBuilder().Build())) + .And(x => x.GivenTheServiceProviderFactoryReturns()) + .When(x => x.WhenIGetTheLoadBalancer()) + .Then(x => x.ThenAnErrorResponseIsReturned()) + .BDDfy(); + } + [Fact] public void should_call_service_provider() { @@ -183,14 +202,30 @@ namespace Ocelot.UnitTests.LoadBalancer Type = type; } - public ILoadBalancer Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) + public Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) { - return new T(); + return new OkResponse(new T()); } public string Type { get; } } + private class BrokenLoadBalancerCreator : ILoadBalancerCreator + where T : ILoadBalancer, new() + { + public BrokenLoadBalancerCreator() + { + Type = typeof(T).Name; + } + + public Response Create(DownstreamReRoute reRoute, IServiceDiscoveryProvider serviceProvider) + { + return new ErrorResponse(new ErrorInvokingLoadBalancerCreator(new Exception())); + } + + public string Type { get; } + } + private class FakeLoadBalancerOne : ILoadBalancer { public Task> Lease(DownstreamContext context) @@ -229,5 +264,19 @@ namespace Ocelot.UnitTests.LoadBalancer throw new System.NotImplementedException(); } } + + private class BrokenLoadBalancer : ILoadBalancer + { + public Task> Lease(DownstreamContext context) + { + throw new System.NotImplementedException(); + } + + public void Release(ServiceHostAndPort hostAndPort) + { + throw new System.NotImplementedException(); + } + } + } } diff --git a/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerCreatorTests.cs b/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerCreatorTests.cs index 1cdcb3ab..46f4208b 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerCreatorTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/NoLoadBalancerCreatorTests.cs @@ -1,20 +1,21 @@ -using Moq; -using Ocelot.Configuration; -using Ocelot.Configuration.Builder; -using Ocelot.LoadBalancer.LoadBalancers; -using Ocelot.ServiceDiscovery.Providers; -using Shouldly; -using TestStack.BDDfy; -using Xunit; - -namespace Ocelot.UnitTests.LoadBalancer +namespace Ocelot.UnitTests.LoadBalancer { + using Moq; + using Ocelot.Configuration; + using Ocelot.Configuration.Builder; + using Ocelot.LoadBalancer.LoadBalancers; + using Ocelot.Responses; + using Ocelot.ServiceDiscovery.Providers; + using Shouldly; + using TestStack.BDDfy; + using Xunit; + public class NoLoadBalancerCreatorTests { private readonly NoLoadBalancerCreator _creator; private readonly Mock _serviceProvider; private DownstreamReRoute _reRoute; - private ILoadBalancer _loadBalancer; + private Response _loadBalancer; private string _typeName; public NoLoadBalancerCreatorTests() @@ -61,7 +62,7 @@ namespace Ocelot.UnitTests.LoadBalancer private void ThenTheLoadBalancerIsReturned() where T : ILoadBalancer { - _loadBalancer.ShouldBeOfType(); + _loadBalancer.Data.ShouldBeOfType(); } private void ThenTheLoadBalancerTypeIs(string type) diff --git a/test/Ocelot.UnitTests/LoadBalancer/RoundRobinCreatorTests.cs b/test/Ocelot.UnitTests/LoadBalancer/RoundRobinCreatorTests.cs index 83f7cb6f..b8c436a2 100644 --- a/test/Ocelot.UnitTests/LoadBalancer/RoundRobinCreatorTests.cs +++ b/test/Ocelot.UnitTests/LoadBalancer/RoundRobinCreatorTests.cs @@ -1,20 +1,21 @@ -using Moq; -using Ocelot.Configuration; -using Ocelot.Configuration.Builder; -using Ocelot.LoadBalancer.LoadBalancers; -using Ocelot.ServiceDiscovery.Providers; -using Shouldly; -using TestStack.BDDfy; -using Xunit; - -namespace Ocelot.UnitTests.LoadBalancer +namespace Ocelot.UnitTests.LoadBalancer { + using Moq; + using Ocelot.Configuration; + using Ocelot.Configuration.Builder; + using Ocelot.LoadBalancer.LoadBalancers; + using Ocelot.Responses; + using Ocelot.ServiceDiscovery.Providers; + using Shouldly; + using TestStack.BDDfy; + using Xunit; + public class RoundRobinCreatorTests { private readonly RoundRobinCreator _creator; private readonly Mock _serviceProvider; private DownstreamReRoute _reRoute; - private ILoadBalancer _loadBalancer; + private Response _loadBalancer; private string _typeName; public RoundRobinCreatorTests() @@ -61,7 +62,7 @@ namespace Ocelot.UnitTests.LoadBalancer private void ThenTheLoadBalancerIsReturned() where T : ILoadBalancer { - _loadBalancer.ShouldBeOfType(); + _loadBalancer.Data.ShouldBeOfType(); } private void ThenTheLoadBalancerTypeIs(string type) diff --git a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs index da2898fc..04a4496f 100644 --- a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs +++ b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs @@ -48,6 +48,7 @@ namespace Ocelot.UnitTests.Responder [Theory] [InlineData(OcelotErrorCode.UnableToCompleteRequestError)] [InlineData(OcelotErrorCode.CouldNotFindLoadBalancerCreator)] + [InlineData(OcelotErrorCode.ErrorInvokingLoadBalancerCreator)] public void should_return_internal_server_error(OcelotErrorCode errorCode) { ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.InternalServerError); @@ -133,7 +134,7 @@ namespace Ocelot.UnitTests.Responder // If this test fails then it's because the number of error codes has changed. // You should make the appropriate changes to the test cases here to ensure // they cover all the error codes, and then modify this assertion. - Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(40, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?"); + Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(41, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?"); } private void ShouldMapErrorToStatusCode(OcelotErrorCode errorCode, HttpStatusCode expectedHttpStatusCode)