From c87fd325aa177786f11ee5e9d8c9c60dc4c0a639 Mon Sep 17 00:00:00 2001 From: Tom Gardham-Pallister Date: Mon, 3 Sep 2018 19:37:06 +0100 Subject: [PATCH 1/2] updating to latest ocelot, tests failing --- .../Ocelot.Provider.Consul.csproj | 2 +- .../ConfigurationInConsulTests.cs | 15 +++++++++------ .../Ocelot.Provider.Consul.AcceptanceTests.csproj | 2 +- .../ServiceDiscoveryTests.cs | 11 ++++------- .../Steps.cs | 1 - .../TwoDownstreamServicesTests.cs | 5 ++++- .../WebSocketTests.cs | 6 ++++-- .../Ocelot.Provider.Consul.Benchmarks.csproj | 2 +- ...Ocelot.Provider.Consul.IntegrationTests.csproj | 4 +--- .../Ocelot.Provider.Consul.ManualTest.csproj | 2 +- .../ConsulServiceDiscoveryProviderTests.cs | 5 ++++- .../Ocelot.Provider.Consul.UnitTests.csproj | 2 +- 12 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj b/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj index 24db863..aaba04b 100644 --- a/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj +++ b/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj @@ -27,7 +27,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs b/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs index 112ce12..67a1137 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs @@ -366,8 +366,9 @@ private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string var base64 = Convert.ToBase64String(bytes); var kvp = new FakeConsulGetResponse(base64); - - await context.Response.WriteJsonAsync(new FakeConsulGetResponse[] { kvp }); + json = JsonConvert.SerializeObject(new FakeConsulGetResponse[] { kvp }); + context.Response.Headers.Add("Content-Type", "application/json"); + await context.Response.WriteAsync(json); } else if (context.Request.Method.ToLower() == "put" && context.Request.Path.Value == "/v1/kv/InternalConfiguration") { @@ -391,7 +392,9 @@ private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string } else if (context.Request.Path.Value == $"/v1/health/service/{serviceName}") { - await context.Response.WriteJsonAsync(_consulServices); + var json = JsonConvert.SerializeObject(_consulServices); + context.Response.Headers.Add("Content-Type", "application/json"); + await context.Response.WriteAsync(json); } }); }) @@ -452,17 +455,17 @@ public void Add(string key, FileConfiguration value, TimeSpan ttl, string region throw new NotImplementedException(); } - public void AddAndDelete(string key, FileConfiguration value, TimeSpan ttl, string region) + public FileConfiguration Get(string key, string region) { throw new NotImplementedException(); } - public FileConfiguration Get(string key, string region) + public void ClearRegion(string region) { throw new NotImplementedException(); } - public void ClearRegion(string region) + public void AddAndDelete(string key, FileConfiguration value, TimeSpan ttl, string region) { throw new NotImplementedException(); } diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj b/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj index c9b1ba8..8c69aef 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj @@ -33,7 +33,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs b/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs index 1f1aa77..44251e2 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs @@ -7,6 +7,7 @@ using Configuration.File; using global::Consul; using Microsoft.AspNetCore.Http; + using Newtonsoft.Json; using Shouldly; using TestStack.BDDfy; using Xunit; @@ -72,7 +73,6 @@ public void should_use_consul_service_discovery_and_load_balance_request() UpstreamHttpMethod = new List { "Get" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, - UseServiceDiscovery = true, } }, GlobalConfiguration = new FileGlobalConfiguration() @@ -128,7 +128,6 @@ public void should_handle_request_to_consul_for_downstream_service_and_make_requ UpstreamHttpMethod = new List { "Get", "Options" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, - UseServiceDiscovery = true, } }, GlobalConfiguration = new FileGlobalConfiguration() @@ -299,7 +298,6 @@ public void should_use_token_to_make_request_to_consul() UpstreamHttpMethod = new List { "Get", "Options" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, - UseServiceDiscovery = true, } }, GlobalConfiguration = new FileGlobalConfiguration() @@ -368,7 +366,6 @@ public void should_send_request_to_service_after_it_becomes_available_in_consul( UpstreamHttpMethod = new List { "Get" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, - UseServiceDiscovery = true, } }, GlobalConfiguration = new FileGlobalConfiguration() @@ -434,7 +431,6 @@ public void should_handle_request_to_poll_consul_for_downstream_service_and_make UpstreamHttpMethod = new List { "Get", "Options" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, - UseServiceDiscovery = true, } }, GlobalConfiguration = new FileGlobalConfiguration() @@ -512,8 +508,9 @@ private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string { _receivedToken = values.First(); } - - await context.Response.WriteJsonAsync(_consulServices); + var json = JsonConvert.SerializeObject(_consulServices); + context.Response.Headers.Add("Content-Type", "application/json"); + await context.Response.WriteAsync(json); } }); } diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/Steps.cs b/test/Ocelot.Provider.Consul.AcceptanceTests/Steps.cs index b53b1b4..e8bd3b1 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/Steps.cs +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/Steps.cs @@ -15,7 +15,6 @@ using Configuration.File; using Configuration.Repository; using DependencyInjection; - using IdentityServer4.AccessTokenValidation; using Infrastructure; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/TwoDownstreamServicesTests.cs b/test/Ocelot.Provider.Consul.AcceptanceTests/TwoDownstreamServicesTests.cs index e883137..a8934d5 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/TwoDownstreamServicesTests.cs +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/TwoDownstreamServicesTests.cs @@ -6,6 +6,7 @@ using Configuration.File; using global::Consul; using Microsoft.AspNetCore.Http; + using Newtonsoft.Json; using TestStack.BDDfy; using Xunit; @@ -97,7 +98,9 @@ private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url) { if (context.Request.Path.Value == "/v1/health/service/product") { - await context.Response.WriteJsonAsync(_serviceEntries); + var json = JsonConvert.SerializeObject(_serviceEntries); + context.Response.Headers.Add("Content-Type", "application/json"); + await context.Response.WriteAsync(json); } }); } diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/WebSocketTests.cs b/test/Ocelot.Provider.Consul.AcceptanceTests/WebSocketTests.cs index 2c5a220..ac8688c 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/WebSocketTests.cs +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/WebSocketTests.cs @@ -9,6 +9,7 @@ using Configuration.File; using global::Consul; using Microsoft.AspNetCore.Http; + using Newtonsoft.Json; using Shouldly; using TestStack.BDDfy; using Xunit; @@ -76,7 +77,6 @@ public void should_proxy_websocket_input_to_downstream_service_and_use_service_d DownstreamScheme = "ws", LoadBalancerOptions = new FileLoadBalancerOptions { Type = "RoundRobin" }, ServiceName = serviceName, - UseServiceDiscovery = true } }, GlobalConfiguration = new FileGlobalConfiguration @@ -130,7 +130,9 @@ private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string { if (context.Request.Path.Value == $"/v1/health/service/{serviceName}") { - await context.Response.WriteJsonAsync(_serviceEntries); + var json = JsonConvert.SerializeObject(_serviceEntries); + context.Response.Headers.Add("Content-Type", "application/json"); + await context.Response.WriteAsync(json); } }); } diff --git a/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj b/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj index 845327b..663fcdc 100644 --- a/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj +++ b/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj @@ -16,7 +16,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj b/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj index c4fd163..bd58552 100644 --- a/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj +++ b/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj @@ -18,10 +18,9 @@ - - + all @@ -35,7 +34,6 @@ - diff --git a/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj b/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj index fdc82b1..b9d3c4e 100644 --- a/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj +++ b/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj @@ -34,7 +34,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.UnitTests/ConsulServiceDiscoveryProviderTests.cs b/test/Ocelot.Provider.Consul.UnitTests/ConsulServiceDiscoveryProviderTests.cs index 03e0837..05ece95 100644 --- a/test/Ocelot.Provider.Consul.UnitTests/ConsulServiceDiscoveryProviderTests.cs +++ b/test/Ocelot.Provider.Consul.UnitTests/ConsulServiceDiscoveryProviderTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Moq; + using Newtonsoft.Json; using Shouldly; using TestStack.BDDfy; using Values; @@ -276,7 +277,9 @@ private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url, string _receivedToken = values.First(); } - await context.Response.WriteJsonAsync(_serviceEntries); + var json = JsonConvert.SerializeObject(_serviceEntries); + context.Response.Headers.Add("Content-Type", "application/json"); + await context.Response.WriteAsync(json); } }); }) diff --git a/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj b/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj index df76812..cf755f7 100644 --- a/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj +++ b/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj @@ -42,7 +42,7 @@ - + all From 523cb3e25902b0bc396130102dd91266246eae97 Mon Sep 17 00:00:00 2001 From: Tom Pallister Date: Mon, 3 Sep 2018 22:03:09 +0100 Subject: [PATCH 2/2] Updated to use latest Ocelot to fix issue with dynamic routing --- Ocelot.Provider.Consul.sln | 3 ++- .../Ocelot.Provider.Consul.csproj | 2 +- .../ConfigurationInConsulTests.cs | 22 +++++++++---------- ...lot.Provider.Consul.AcceptanceTests.csproj | 2 +- .../ServiceDiscoveryTests.cs | 6 ----- .../Ocelot.Provider.Consul.Benchmarks.csproj | 2 +- ...ot.Provider.Consul.IntegrationTests.csproj | 2 +- .../Ocelot.Provider.Consul.ManualTest.csproj | 2 +- .../Ocelot.Provider.Consul.UnitTests.csproj | 2 +- 9 files changed, 19 insertions(+), 24 deletions(-) diff --git a/Ocelot.Provider.Consul.sln b/Ocelot.Provider.Consul.sln index 6b50ad2..e73a6a4 100644 --- a/Ocelot.Provider.Consul.sln +++ b/Ocelot.Provider.Consul.sln @@ -1,4 +1,5 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27130.2036 MinimumVisualStudioVersion = 10.0.40219.1 diff --git a/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj b/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj index aaba04b..d6402e5 100644 --- a/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj +++ b/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj @@ -27,7 +27,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs b/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs index 67a1137..49ab386 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/ConfigurationInConsulTests.cs @@ -254,20 +254,20 @@ public void should_handle_request_to_consul_for_downstream_service_and_make_requ var consulConfig = new FileConfiguration { DynamicReRoutes = new List + { + new FileDynamicReRoute { - new FileDynamicReRoute + ServiceName = serviceName, + RateLimitRule = new FileRateLimitRule() { - ServiceName = serviceName, - RateLimitRule = new FileRateLimitRule() - { - EnableRateLimiting = true, - ClientWhitelist = new List(), - Limit = 3, - Period = "1s", - PeriodTimespan = 1000 - } + EnableRateLimiting = true, + ClientWhitelist = new List(), + Limit = 3, + Period = "1s", + PeriodTimespan = 1000 } - }, + } + }, GlobalConfiguration = new FileGlobalConfiguration { ServiceDiscoveryProvider = new FileServiceDiscoveryProvider diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj b/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj index 8c69aef..2ff0800 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/Ocelot.Provider.Consul.AcceptanceTests.csproj @@ -33,7 +33,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs b/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs index 44251e2..ac655cd 100644 --- a/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs +++ b/test/Ocelot.Provider.Consul.AcceptanceTests/ServiceDiscoveryTests.cs @@ -186,12 +186,6 @@ public void should_handle_request_to_consul_for_downstream_service_and_make_requ AllowAutoRedirect = true, UseCookieContainer = true, UseTracing = false - }, - QoSOptions = new FileQoSOptions - { - TimeoutValue = 100, - DurationOfBreak = 1000, - ExceptionsAllowedBeforeBreaking = 1 } } }; diff --git a/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj b/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj index 663fcdc..9cfda1f 100644 --- a/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj +++ b/test/Ocelot.Provider.Consul.Benchmarks/Ocelot.Provider.Consul.Benchmarks.csproj @@ -16,7 +16,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj b/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj index bd58552..b62cd45 100644 --- a/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj +++ b/test/Ocelot.Provider.Consul.IntegrationTests/Ocelot.Provider.Consul.IntegrationTests.csproj @@ -20,7 +20,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj b/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj index b9d3c4e..b35a580 100644 --- a/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj +++ b/test/Ocelot.Provider.Consul.ManualTest/Ocelot.Provider.Consul.ManualTest.csproj @@ -34,7 +34,7 @@ - + all diff --git a/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj b/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj index cf755f7..e153185 100644 --- a/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj +++ b/test/Ocelot.Provider.Consul.UnitTests/Ocelot.Provider.Consul.UnitTests.csproj @@ -42,7 +42,7 @@ - + all