mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:18:17 +08:00
Feature/fix unstable int tests (#376)
* updated packages but build wont work * #245 implementing more stable rafty * #245 OK so these raft integration tests are passing everytime on my local mac now...lets see about the build servergit log * #245 added donation button * #245 removed file we dont need
This commit is contained in:
@ -1,50 +1,50 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>0.0.0-dev</VersionPrefix>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
|
||||
<AssemblyName>Ocelot.IntegrationTests</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<PackageId>Ocelot.IntegrationTests</PackageId>
|
||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64</RuntimeIdentifiers>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<CodeAnalysisRuleSet>..\..\codeanalysis.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Update="peers.json;appsettings.json;idsrv3test.pfx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ocelot\Ocelot.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="IdentityServer4" Version="2.2.0" />
|
||||
<PackageReference Include="Shouldly" Version="3.0.0" />
|
||||
<PackageReference Include="TestStack.BDDfy" Version="4.3.2" />
|
||||
<PackageReference Include="Consul" Version="0.7.2.4" />
|
||||
<PackageReference Include="Rafty" Version="0.4.3" />
|
||||
<PackageReference Include="Microsoft.Data.SQLite" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>0.0.0-dev</VersionPrefix>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
|
||||
<AssemblyName>Ocelot.IntegrationTests</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<PackageId>Ocelot.IntegrationTests</PackageId>
|
||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64</RuntimeIdentifiers>
|
||||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||
<CodeAnalysisRuleSet>..\..\codeanalysis.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Update="peers.json;appsettings.json;idsrv3test.pfx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Ocelot\Ocelot.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="IdentityServer4" Version="2.2.0" />
|
||||
<PackageReference Include="Shouldly" Version="3.0.0" />
|
||||
<PackageReference Include="TestStack.BDDfy" Version="4.3.2" />
|
||||
<PackageReference Include="Consul" Version="0.7.2.4" />
|
||||
<PackageReference Include="Rafty" Version="0.4.4" />
|
||||
<PackageReference Include="Microsoft.Data.SQLite" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -23,6 +23,7 @@ using Ocelot.Middleware;
|
||||
|
||||
namespace Ocelot.IntegrationTests
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
public class RaftTests : IDisposable
|
||||
@ -31,7 +32,7 @@ namespace Ocelot.IntegrationTests
|
||||
private readonly List<IWebHostBuilder> _webHostBuilders;
|
||||
private readonly List<Thread> _threads;
|
||||
private FilePeers _peers;
|
||||
private readonly HttpClient _httpClient;
|
||||
private HttpClient _httpClient;
|
||||
private readonly HttpClient _httpClientForAssertions;
|
||||
private BearerToken _token;
|
||||
private HttpResponseMessage _response;
|
||||
@ -42,18 +43,28 @@ namespace Ocelot.IntegrationTests
|
||||
{
|
||||
_output = output;
|
||||
_httpClientForAssertions = new HttpClient();
|
||||
_httpClient = new HttpClient();
|
||||
var ocelotBaseUrl = "http://localhost:5000";
|
||||
_httpClient.BaseAddress = new Uri(ocelotBaseUrl);
|
||||
_webHostBuilders = new List<IWebHostBuilder>();
|
||||
_builders = new List<IWebHost>();
|
||||
_threads = new List<Thread>();
|
||||
}
|
||||
|
||||
[Fact(Skip = "still broken waiting for work in rafty")]
|
||||
public void should_persist_command_to_five_servers()
|
||||
[Fact]
|
||||
public async Task should_persist_command_to_five_servers()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
var peers = new List<FilePeer>
|
||||
{
|
||||
new FilePeer {HostAndPort = "http://localhost:5000"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5001"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5002"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5003"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5004"}
|
||||
};
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
GlobalConfiguration = new FileGlobalConfiguration
|
||||
{
|
||||
@ -101,20 +112,34 @@ namespace Ocelot.IntegrationTests
|
||||
};
|
||||
|
||||
var command = new UpdateFileConfiguration(updatedConfiguration);
|
||||
GivenThePeersAre(peers);
|
||||
GivenThereIsAConfiguration(configuration);
|
||||
GivenFiveServersAreRunning();
|
||||
GivenIHaveAnOcelotToken("/administration");
|
||||
WhenISendACommandIntoTheCluster(command);
|
||||
await GivenIHaveAnOcelotToken("/administration");
|
||||
await WhenISendACommandIntoTheCluster(command);
|
||||
Thread.Sleep(5000);
|
||||
ThenTheCommandIsReplicatedToAllStateMachines(command);
|
||||
await ThenTheCommandIsReplicatedToAllStateMachines(command);
|
||||
}
|
||||
|
||||
[Fact(Skip = "still broken waiting for work in rafty")]
|
||||
public void should_persist_command_to_five_servers_when_using_administration_api()
|
||||
[Fact]
|
||||
public async Task should_persist_command_to_five_servers_when_using_administration_api()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
};
|
||||
var peers = new List<FilePeer>
|
||||
{
|
||||
new FilePeer {HostAndPort = "http://localhost:5005"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5006"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5007"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5008"},
|
||||
|
||||
new FilePeer {HostAndPort = "http://localhost:5009"}
|
||||
};
|
||||
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
};
|
||||
|
||||
var updatedConfiguration = new FileConfiguration
|
||||
{
|
||||
@ -154,17 +179,29 @@ namespace Ocelot.IntegrationTests
|
||||
};
|
||||
|
||||
var command = new UpdateFileConfiguration(updatedConfiguration);
|
||||
GivenThePeersAre(peers);
|
||||
GivenThereIsAConfiguration(configuration);
|
||||
GivenFiveServersAreRunning();
|
||||
GivenIHaveAnOcelotToken("/administration");
|
||||
await GivenIHaveAnOcelotToken("/administration");
|
||||
GivenIHaveAddedATokenToMyRequest();
|
||||
WhenIPostOnTheApiGateway("/administration/configuration", updatedConfiguration);
|
||||
ThenTheCommandIsReplicatedToAllStateMachines(command);
|
||||
await WhenIPostOnTheApiGateway("/administration/configuration", updatedConfiguration);
|
||||
await ThenTheCommandIsReplicatedToAllStateMachines(command);
|
||||
}
|
||||
|
||||
private void WhenISendACommandIntoTheCluster(UpdateFileConfiguration command)
|
||||
private void GivenThePeersAre(List<FilePeer> peers)
|
||||
{
|
||||
bool SendCommand()
|
||||
FilePeers filePeers = new FilePeers();
|
||||
filePeers.Peers.AddRange(peers);
|
||||
var json = JsonConvert.SerializeObject(filePeers);
|
||||
File.WriteAllText("peers.json", json);
|
||||
_httpClient = new HttpClient();
|
||||
var ocelotBaseUrl = peers[0].HostAndPort;
|
||||
_httpClient.BaseAddress = new Uri(ocelotBaseUrl);
|
||||
}
|
||||
|
||||
private async Task WhenISendACommandIntoTheCluster(UpdateFileConfiguration command)
|
||||
{
|
||||
async Task<bool> SendCommand()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -174,13 +211,13 @@ namespace Ocelot.IntegrationTests
|
||||
TypeNameHandling = TypeNameHandling.All
|
||||
});
|
||||
var httpContent = new StringContent(json);
|
||||
httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
||||
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken);
|
||||
var response = httpClient.PostAsync($"{p.HostAndPort}/administration/raft/command", httpContent).GetAwaiter().GetResult();
|
||||
var response = await httpClient.PostAsync($"{p.HostAndPort}/administration/raft/command", httpContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var errorResult = JsonConvert.DeserializeObject<ErrorResponse<UpdateFileConfiguration>>(content);
|
||||
|
||||
@ -206,13 +243,19 @@ namespace Ocelot.IntegrationTests
|
||||
}
|
||||
}
|
||||
|
||||
var commandSent = WaitFor(20000).Until(() => SendCommand());
|
||||
var commandSent = await WaitFor(40000).Until(async () =>
|
||||
{
|
||||
var result = await SendCommand();
|
||||
Thread.Sleep(1000);
|
||||
return result;
|
||||
});
|
||||
|
||||
commandSent.ShouldBeTrue();
|
||||
}
|
||||
|
||||
private void ThenTheCommandIsReplicatedToAllStateMachines(UpdateFileConfiguration expecteds)
|
||||
private async Task ThenTheCommandIsReplicatedToAllStateMachines(UpdateFileConfiguration expecteds)
|
||||
{
|
||||
bool CommandCalledOnAllStateMachines()
|
||||
async Task<bool> CommandCalledOnAllStateMachines()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -232,8 +275,8 @@ namespace Ocelot.IntegrationTests
|
||||
}
|
||||
|
||||
_httpClientForAssertions.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken);
|
||||
var result = _httpClientForAssertions.GetAsync($"{peer.HostAndPort}/administration/configuration").Result;
|
||||
var json = result.Content.ReadAsStringAsync().Result;
|
||||
var result = await _httpClientForAssertions.GetAsync($"{peer.HostAndPort}/administration/configuration");
|
||||
var json = await result.Content.ReadAsStringAsync();
|
||||
var response = JsonConvert.DeserializeObject<FileConfiguration>(json, new JsonSerializerSettings{TypeNameHandling = TypeNameHandling.All});
|
||||
response.GlobalConfiguration.RequestIdKey.ShouldBe(expecteds.Configuration.GlobalConfiguration.RequestIdKey);
|
||||
response.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.Configuration.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
||||
@ -268,19 +311,29 @@ namespace Ocelot.IntegrationTests
|
||||
}
|
||||
}
|
||||
|
||||
var commandOnAllStateMachines = WaitFor(20000).Until(() => CommandCalledOnAllStateMachines());
|
||||
var commandOnAllStateMachines = await WaitFor(40000).Until(async () =>
|
||||
{
|
||||
var result = await CommandCalledOnAllStateMachines();
|
||||
Thread.Sleep(1000);
|
||||
return result;
|
||||
});
|
||||
|
||||
commandOnAllStateMachines.ShouldBeTrue();
|
||||
}
|
||||
|
||||
private void WhenIPostOnTheApiGateway(string url, FileConfiguration updatedConfiguration)
|
||||
private async Task WhenIPostOnTheApiGateway(string url, FileConfiguration updatedConfiguration)
|
||||
{
|
||||
bool SendCommand()
|
||||
async Task<bool> SendCommand()
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(updatedConfiguration);
|
||||
|
||||
var content = new StringContent(json);
|
||||
|
||||
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
_response = _httpClient.PostAsync(url, content).Result;
|
||||
var responseContent = _response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
_response = await _httpClient.PostAsync(url, content);
|
||||
|
||||
var responseContent = await _response.Content.ReadAsStringAsync();
|
||||
|
||||
if(responseContent == "There was a problem. This error message sucks raise an issue in GitHub.")
|
||||
{
|
||||
@ -295,8 +348,14 @@ namespace Ocelot.IntegrationTests
|
||||
return _response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
var commandSent = WaitFor(20000).Until(() => SendCommand());
|
||||
commandSent.ShouldBeTrue();
|
||||
var commandSent = await WaitFor(40000).Until(async () =>
|
||||
{
|
||||
var result = await SendCommand();
|
||||
Thread.Sleep(1000);
|
||||
return result;
|
||||
});
|
||||
|
||||
commandSent.ShouldBeTrue();
|
||||
}
|
||||
|
||||
private void GivenIHaveAddedATokenToMyRequest()
|
||||
@ -304,9 +363,9 @@ namespace Ocelot.IntegrationTests
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken);
|
||||
}
|
||||
|
||||
private void GivenIHaveAnOcelotToken(string adminPath)
|
||||
private async Task GivenIHaveAnOcelotToken(string adminPath)
|
||||
{
|
||||
bool AddToken()
|
||||
async Task<bool> AddToken()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -320,8 +379,8 @@ namespace Ocelot.IntegrationTests
|
||||
};
|
||||
var content = new FormUrlEncodedContent(formData);
|
||||
|
||||
var response = _httpClient.PostAsync(tokenUrl, content).Result;
|
||||
var responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
var response = await _httpClient.PostAsync(tokenUrl, content);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return false;
|
||||
@ -329,7 +388,7 @@ namespace Ocelot.IntegrationTests
|
||||
|
||||
_token = JsonConvert.DeserializeObject<BearerToken>(responseContent);
|
||||
var configPath = $"{adminPath}/.well-known/openid-configuration";
|
||||
response = _httpClient.GetAsync(configPath).Result;
|
||||
response = await _httpClient.GetAsync(configPath);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch(Exception)
|
||||
@ -338,7 +397,13 @@ namespace Ocelot.IntegrationTests
|
||||
}
|
||||
}
|
||||
|
||||
var addToken = WaitFor(20000).Until(() => AddToken());
|
||||
var addToken = await WaitFor(40000).Until(async () =>
|
||||
{
|
||||
var result = await AddToken();
|
||||
Thread.Sleep(1000);
|
||||
return result;
|
||||
});
|
||||
|
||||
addToken.ShouldBeTrue();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user