mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
#245 hacked these tests around and they are now passing 5 runs in a row on my mac, lets see on build server
This commit is contained in:
parent
6793278597
commit
003fff8b24
@ -41,6 +41,8 @@ namespace Ocelot.Configuration
|
|||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Post([FromBody]FileConfiguration fileConfiguration)
|
public async Task<IActionResult> Post([FromBody]FileConfiguration fileConfiguration)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
//todo - this code is a bit shit sort it out..
|
//todo - this code is a bit shit sort it out..
|
||||||
var test = _provider.GetService(typeof(INode));
|
var test = _provider.GetService(typeof(INode));
|
||||||
@ -65,5 +67,10 @@ namespace Ocelot.Configuration
|
|||||||
|
|
||||||
return new OkObjectResult(fileConfiguration);
|
return new OkObjectResult(fileConfiguration);
|
||||||
}
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return new BadRequestObjectResult($"{e.Message}:{e.StackTrace}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,8 @@ namespace Ocelot.Raft
|
|||||||
var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/command", content).GetAwaiter().GetResult();
|
var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/command", content).GetAwaiter().GetResult();
|
||||||
if(response.IsSuccessStatusCode)
|
if(response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<OkResponse<T>>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), _jsonSerializerSettings);
|
var okResponse = JsonConvert.DeserializeObject<OkResponse<ICommand>>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), _jsonSerializerSettings);
|
||||||
|
return new OkResponse<T>((T)okResponse.Command);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ namespace Ocelot.IntegrationTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Skip = "This tests is flakey at the moment so ignoring will be fixed long term see https://github.com/TomPallister/Ocelot/issues/245")]
|
[Fact]
|
||||||
public void should_persist_command_to_five_servers()
|
public void should_persist_command_to_five_servers()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
@ -113,13 +113,12 @@ namespace Ocelot.IntegrationTests
|
|||||||
var command = new UpdateFileConfiguration(updatedConfiguration);
|
var command = new UpdateFileConfiguration(updatedConfiguration);
|
||||||
GivenThereIsAConfiguration(configuration);
|
GivenThereIsAConfiguration(configuration);
|
||||||
GivenFiveServersAreRunning();
|
GivenFiveServersAreRunning();
|
||||||
GivenALeaderIsElected();
|
|
||||||
GivenIHaveAnOcelotToken("/administration");
|
GivenIHaveAnOcelotToken("/administration");
|
||||||
WhenISendACommandIntoTheCluster(command);
|
WhenISendACommandIntoTheCluster(command);
|
||||||
ThenTheCommandIsReplicatedToAllStateMachines(command);
|
ThenTheCommandIsReplicatedToAllStateMachines(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Skip = "This tests is flakey at the moment so ignoring will be fixed long term see https://github.com/TomPallister/Ocelot/issues/245")]
|
[Fact]
|
||||||
public void should_persist_command_to_five_servers_when_using_administration_api()
|
public void should_persist_command_to_five_servers_when_using_administration_api()
|
||||||
{
|
{
|
||||||
var configuration = new FileConfiguration
|
var configuration = new FileConfiguration
|
||||||
@ -166,7 +165,6 @@ namespace Ocelot.IntegrationTests
|
|||||||
var command = new UpdateFileConfiguration(updatedConfiguration);
|
var command = new UpdateFileConfiguration(updatedConfiguration);
|
||||||
GivenThereIsAConfiguration(configuration);
|
GivenThereIsAConfiguration(configuration);
|
||||||
GivenFiveServersAreRunning();
|
GivenFiveServersAreRunning();
|
||||||
GivenALeaderIsElected();
|
|
||||||
GivenIHaveAnOcelotToken("/administration");
|
GivenIHaveAnOcelotToken("/administration");
|
||||||
GivenIHaveAddedATokenToMyRequest();
|
GivenIHaveAddedATokenToMyRequest();
|
||||||
WhenIPostOnTheApiGateway("/administration/configuration", updatedConfiguration);
|
WhenIPostOnTheApiGateway("/administration/configuration", updatedConfiguration);
|
||||||
@ -174,6 +172,8 @@ namespace Ocelot.IntegrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void WhenISendACommandIntoTheCluster(UpdateFileConfiguration command)
|
private void WhenISendACommandIntoTheCluster(UpdateFileConfiguration command)
|
||||||
|
{
|
||||||
|
bool SendCommand()
|
||||||
{
|
{
|
||||||
var p = _peers.Peers.First();
|
var p = _peers.Peers.First();
|
||||||
var json = JsonConvert.SerializeObject(command,new JsonSerializerSettings() {
|
var json = JsonConvert.SerializeObject(command,new JsonSerializerSettings() {
|
||||||
@ -187,25 +187,31 @@ namespace Ocelot.IntegrationTests
|
|||||||
var response = httpClient.PostAsync($"{p.HostAndPort}/administration/raft/command", httpContent).GetAwaiter().GetResult();
|
var response = httpClient.PostAsync($"{p.HostAndPort}/administration/raft/command", httpContent).GetAwaiter().GetResult();
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||||
var result = JsonConvert.DeserializeObject<OkResponse<UpdateFileConfiguration>>(content);
|
|
||||||
result.Command.Configuration.ReRoutes.Count.ShouldBe(2);
|
var errorResult = JsonConvert.DeserializeObject<ErrorResponse<UpdateFileConfiguration>>(content);
|
||||||
|
|
||||||
|
if(!string.IsNullOrEmpty(errorResult.Error))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//dirty sleep to make sure command replicated...
|
var okResult = JsonConvert.DeserializeObject<OkResponse<UpdateFileConfiguration>>(content);
|
||||||
var stopwatch = Stopwatch.StartNew();
|
|
||||||
while(stopwatch.ElapsedMilliseconds < 10000)
|
if(okResult.Command.Configuration.ReRoutes.Count == 2)
|
||||||
{
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var commandSent = WaitFor(20000).Until(() => SendCommand());
|
||||||
|
commandSent.ShouldBeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
private void ThenTheCommandIsReplicatedToAllStateMachines(UpdateFileConfiguration expecteds)
|
private void ThenTheCommandIsReplicatedToAllStateMachines(UpdateFileConfiguration expecteds)
|
||||||
{
|
{
|
||||||
//dirty sleep to give a chance to replicate...
|
|
||||||
var stopwatch = Stopwatch.StartNew();
|
|
||||||
while(stopwatch.ElapsedMilliseconds < 2000)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CommandCalledOnAllStateMachines()
|
bool CommandCalledOnAllStateMachines()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -266,11 +272,35 @@ namespace Ocelot.IntegrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void WhenIPostOnTheApiGateway(string url, FileConfiguration updatedConfiguration)
|
private void WhenIPostOnTheApiGateway(string url, FileConfiguration updatedConfiguration)
|
||||||
|
{
|
||||||
|
bool SendCommand()
|
||||||
{
|
{
|
||||||
var json = JsonConvert.SerializeObject(updatedConfiguration);
|
var json = JsonConvert.SerializeObject(updatedConfiguration);
|
||||||
var content = new StringContent(json);
|
var content = new StringContent(json);
|
||||||
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||||
_response = _httpClient.PostAsync(url, content).Result;
|
_response = _httpClient.PostAsync(url, content).Result;
|
||||||
|
var responseContent = _response.Content.ReadAsStringAsync().Result;
|
||||||
|
|
||||||
|
//Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
//Console.WriteLine(responseContent);
|
||||||
|
//Console.WriteLine(_response.StatusCode);
|
||||||
|
//Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
|
if(responseContent == "There was a problem. This error message sucks raise an issue in GitHub.")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(string.IsNullOrEmpty(responseContent))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _response.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
var commandSent = WaitFor(20000).Until(() => SendCommand());
|
||||||
|
commandSent.ShouldBeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenIHaveAddedATokenToMyRequest()
|
private void GivenIHaveAddedATokenToMyRequest()
|
||||||
@ -279,6 +309,10 @@ namespace Ocelot.IntegrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void GivenIHaveAnOcelotToken(string adminPath)
|
private void GivenIHaveAnOcelotToken(string adminPath)
|
||||||
|
{
|
||||||
|
bool AddToken()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var tokenUrl = $"{adminPath}/connect/token";
|
var tokenUrl = $"{adminPath}/connect/token";
|
||||||
var formData = new List<KeyValuePair<string, string>>
|
var formData = new List<KeyValuePair<string, string>>
|
||||||
@ -292,11 +326,24 @@ namespace Ocelot.IntegrationTests
|
|||||||
|
|
||||||
var response = _httpClient.PostAsync(tokenUrl, content).Result;
|
var response = _httpClient.PostAsync(tokenUrl, content).Result;
|
||||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||||
response.EnsureSuccessStatusCode();
|
if(!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
_token = JsonConvert.DeserializeObject<BearerToken>(responseContent);
|
_token = JsonConvert.DeserializeObject<BearerToken>(responseContent);
|
||||||
var configPath = $"{adminPath}/.well-known/openid-configuration";
|
var configPath = $"{adminPath}/.well-known/openid-configuration";
|
||||||
response = _httpClient.GetAsync(configPath).Result;
|
response = _httpClient.GetAsync(configPath).Result;
|
||||||
response.EnsureSuccessStatusCode();
|
return response.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var addToken = WaitFor(20000).Until(() => AddToken());
|
||||||
|
addToken.ShouldBeTrue();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenThereIsAConfiguration(FileConfiguration fileConfiguration)
|
private void GivenThereIsAConfiguration(FileConfiguration fileConfiguration)
|
||||||
@ -380,14 +427,5 @@ namespace Ocelot.IntegrationTests
|
|||||||
_threads.Add(thread);
|
_threads.Add(thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenALeaderIsElected()
|
|
||||||
{
|
|
||||||
//dirty sleep to make sure we have a leader
|
|
||||||
var stopwatch = Stopwatch.StartNew();
|
|
||||||
while(stopwatch.ElapsedMilliseconds < 20000)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user