mirror of https://github.com/dotnet/tye.git
committed by
GitHub
12 changed files with 254 additions and 73 deletions
@ -0,0 +1,53 @@ |
|||||
|
using System; |
||||
|
using System.Net; |
||||
|
using System.Net.Http; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
|
||||
|
namespace E2ETest |
||||
|
{ |
||||
|
public class RetryHandler : DelegatingHandler |
||||
|
{ |
||||
|
private static readonly int MaxRetries = 5; |
||||
|
private static readonly TimeSpan InitialRetryDelay = TimeSpan.FromMilliseconds(100); |
||||
|
|
||||
|
public RetryHandler(HttpMessageHandler innerHandler) |
||||
|
: base(innerHandler) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
protected override async Task<HttpResponseMessage> SendAsync( |
||||
|
HttpRequestMessage request, |
||||
|
CancellationToken cancellationToken) |
||||
|
{ |
||||
|
HttpResponseMessage? response = null; |
||||
|
var delay = InitialRetryDelay; |
||||
|
for (var i = 0; i < MaxRetries; i++) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
response = await base.SendAsync(request, cancellationToken); |
||||
|
} |
||||
|
catch (Exception) |
||||
|
{ |
||||
|
if (i == MaxRetries - 1) |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (response != null && |
||||
|
(response.IsSuccessStatusCode || response.StatusCode != (HttpStatusCode)503)) |
||||
|
{ |
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
await Task.Delay(delay, cancellationToken); |
||||
|
delay *= 2; |
||||
|
} |
||||
|
|
||||
|
throw new TimeoutException("Could not reach response after "); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Net; |
||||
|
using System.Net.Http; |
||||
|
using System.Threading.Tasks; |
||||
|
using Tye.ConfigModel; |
||||
|
using Tye.Hosting; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace E2ETest |
||||
|
{ |
||||
|
public class TyeRunTest |
||||
|
{ |
||||
|
[Fact] |
||||
|
public async Task SingleProjectTest() |
||||
|
{ |
||||
|
var application = ConfigFactory.FromFile(new FileInfo(Path.Combine(GetSolutionRootDirectory("tye"), "samples", "single-project", "test-project", "test-project.csproj"))); |
||||
|
var host = new TyeHost(application.ToHostingApplication(), new string[0]); |
||||
|
var webApplication = await host.StartAsync(); |
||||
|
try |
||||
|
{ |
||||
|
var handler = new HttpClientHandler |
||||
|
{ |
||||
|
ServerCertificateCustomValidationCallback = (a, b, c, d) => true, |
||||
|
AllowAutoRedirect = false |
||||
|
}; |
||||
|
|
||||
|
var client = new HttpClient(new RetryHandler(handler)); |
||||
|
|
||||
|
// Make sure dashboard and applications are up.
|
||||
|
// Dashboard should be hosted in same process.
|
||||
|
var dashboardResponse = await client.GetStringAsync(new Uri(webApplication.Addresses.First())); |
||||
|
|
||||
|
// Only one service for single application.
|
||||
|
var service = application.Services.First(); |
||||
|
var binding = service.Bindings.First(); |
||||
|
|
||||
|
var protocol = binding.Protocol?.Length != 0 ? binding.Protocol : "http"; |
||||
|
var hostName = binding.Host != null && binding.Host.Length != 0 ? binding.Host : "localhost"; |
||||
|
|
||||
|
var uriString = $"{protocol}://{hostName}:{binding.Port}"; |
||||
|
|
||||
|
// Confirm that the uri is in the dashboard response.
|
||||
|
Assert.Contains(uriString, dashboardResponse); |
||||
|
|
||||
|
var uriBackendProcess = new Uri(uriString); |
||||
|
|
||||
|
// This isn't reliable right now because micronetes only guarantees the process starts, not that
|
||||
|
// that kestrel started.
|
||||
|
var appResponse = await client.GetAsync(uriBackendProcess); |
||||
|
Assert.Equal(HttpStatusCode.OK, appResponse.StatusCode); |
||||
|
} |
||||
|
finally |
||||
|
{ |
||||
|
await host.StopAsync(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// https://github.com/dotnet/aspnetcore/blob/5a0526dfd991419d5bce0d8ea525b50df2e37b04/src/Testing/src/TestPathUtilities.cs
|
||||
|
// This can get into a bad pattern for having crazy paths in places. Eventually, especially if we use helix,
|
||||
|
// we may want to avoid relying on sln position.
|
||||
|
public static string GetSolutionRootDirectory(string solution) |
||||
|
{ |
||||
|
var applicationBasePath = AppContext.BaseDirectory; |
||||
|
var directoryInfo = new DirectoryInfo(applicationBasePath); |
||||
|
|
||||
|
do |
||||
|
{ |
||||
|
var projectFileInfo = new FileInfo(Path.Combine(directoryInfo.FullName, $"{solution}.sln")); |
||||
|
if (projectFileInfo.Exists) |
||||
|
{ |
||||
|
return projectFileInfo.DirectoryName; |
||||
|
} |
||||
|
|
||||
|
directoryInfo = directoryInfo.Parent; |
||||
|
} |
||||
|
while (directoryInfo.Parent != null); |
||||
|
|
||||
|
throw new Exception($"Solution file {solution}.sln could not be found in {applicationBasePath} or its parent directories."); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,14 +0,0 @@ |
|||||
using System; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace E2ETest |
|
||||
{ |
|
||||
public class UnitTest1 |
|
||||
{ |
|
||||
[Fact] |
|
||||
public void Test1() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue