wip: added some sleep time into service discovery test as I think Im overloading the test server, sometimes it just returns 404 when Ocelot makes a request to it

This commit is contained in:
Tom Gardham-Pallister 2017-02-05 22:00:23 +00:00
parent d91242ac2c
commit c3e60ac08a
2 changed files with 37 additions and 15 deletions

View File

@ -37,8 +37,6 @@ namespace Ocelot.AcceptanceTests
var downstreamServiceOneUrl = "http://localhost:50879"; var downstreamServiceOneUrl = "http://localhost:50879";
var downstreamServiceTwoUrl = "http://localhost:50880"; var downstreamServiceTwoUrl = "http://localhost:50880";
var fakeConsulServiceDiscoveryUrl = "http://localhost:8500"; var fakeConsulServiceDiscoveryUrl = "http://localhost:8500";
var downstreamServiceOneCounter = 0;
var downstreamServiceTwoCounter = 0;
var serviceEntryOne = new ServiceEntry() var serviceEntryOne = new ServiceEntry()
{ {
Service = new AgentService() Service = new AgentService()
@ -153,6 +151,8 @@ namespace Ocelot.AcceptanceTests
.Configure(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{
try
{ {
var response = string.Empty; var response = string.Empty;
lock (_syncLock) lock (_syncLock)
@ -162,6 +162,11 @@ namespace Ocelot.AcceptanceTests
} }
context.Response.StatusCode = statusCode; context.Response.StatusCode = statusCode;
await context.Response.WriteAsync(response); await context.Response.WriteAsync(response);
}
catch (System.Exception exception)
{
await context.Response.WriteAsync(exception.StackTrace);
}
}); });
}) })
.Build(); .Build();
@ -180,6 +185,8 @@ namespace Ocelot.AcceptanceTests
.Configure(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{
try
{ {
var response = string.Empty; var response = string.Empty;
lock (_syncLock) lock (_syncLock)
@ -187,8 +194,15 @@ namespace Ocelot.AcceptanceTests
_counterTwo++; _counterTwo++;
response = _counterTwo.ToString(); response = _counterTwo.ToString();
} }
context.Response.StatusCode = statusCode; context.Response.StatusCode = statusCode;
await context.Response.WriteAsync(response); await context.Response.WriteAsync(response);
}
catch (System.Exception exception)
{
await context.Response.WriteAsync(exception.StackTrace);
}
}); });
}) })
.Build(); .Build();

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using CacheManager.Core; using CacheManager.Core;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@ -30,6 +31,12 @@ namespace Ocelot.AcceptanceTests
private BearerToken _token; private BearerToken _token;
public HttpClient OcelotClient => _ocelotClient; public HttpClient OcelotClient => _ocelotClient;
public string RequestIdKey = "OcRequestId"; public string RequestIdKey = "OcRequestId";
private Random _random;
public Steps()
{
_random = new Random();
}
public void GivenThereIsAConfiguration(FileConfiguration fileConfiguration) public void GivenThereIsAConfiguration(FileConfiguration fileConfiguration)
{ {
@ -162,6 +169,7 @@ namespace Ocelot.AcceptanceTests
{ {
var urlCopy = url; var urlCopy = url;
tasks[i] = GetForServiceDiscoveryTest(urlCopy); tasks[i] = GetForServiceDiscoveryTest(urlCopy);
Thread.Sleep(_random.Next(40,60));
} }
Task.WaitAll(tasks); Task.WaitAll(tasks);
@ -171,7 +179,7 @@ namespace Ocelot.AcceptanceTests
{ {
var response = await _ocelotClient.GetAsync(url); var response = await _ocelotClient.GetAsync(url);
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
var count = int.Parse(content); int count = int.Parse(content);
count.ShouldBeGreaterThan(0); count.ShouldBeGreaterThan(0);
} }