Skip to content

[Templates] Separate F# from C# tests, unskip tests, include reliability improvements #14261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/ProjectTemplates/test/EmptyWebTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ public EmptyWebTemplateTest(ProjectFactoryFixture projectFactory, ITestOutputHel

public ITestOutputHelper Output { get; }

[Theory]
[InlineData(null)]
[InlineData("F#")]
public async Task EmptyWebTemplateAsync(string languageOverride)
[Fact]
public async Task EmptyWebTemplateCSharp()
{
await EmtpyTemplateCore(languageOverride: null);
}

[Fact]
public async Task EmptyWebTemplateFSharp()
{
await EmtpyTemplateCore("F#");
}

private async Task EmtpyTemplateCore(string languageOverride)
{
Project = await ProjectFactory.GetOrCreateProject("empty" + (languageOverride == "F#" ? "fsharp" : "csharp"), Output);

Expand Down
32 changes: 27 additions & 5 deletions src/ProjectTemplates/test/Helpers/AspNetProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public AspNetProcess(

var arguments = published ? $"exec {dllPath}" : "run";
Process = ProcessEx.Run(output, workingDirectory, DotNetMuxer.MuxerPathOrDefault(), arguments, envVars: environmentVariables);
if(hasListeningUri)
if (hasListeningUri)
{
ListeningUri = GetListeningUri(output);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public async Task ContainsLinks(Page page)
HttpMethod.Get,
new Uri(ListeningUri, page.Url));

var response = await _httpClient.SendAsync(request);
var response = await RequestWithRetries(client => client.SendAsync(request), _httpClient);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var parser = new HtmlParser();
Expand Down Expand Up @@ -141,14 +141,36 @@ public async Task ContainsLinks(Page page)
Assert.True(string.Equals(anchor.Href, expectedLink), $"Expected next link to be {expectedLink} but it was {anchor.Href}.");
var result = await RetryHelper.RetryRequest(async () =>
{
return await _httpClient.GetAsync(anchor.Href);
return await RequestWithRetries(client => client.GetAsync(anchor.Href), _httpClient);
}, logger: NullLogger.Instance);

Assert.True(IsSuccessStatusCode(result), $"{anchor.Href} is a broken link!");
}
}
}

private async Task<T> RequestWithRetries<T>(Func<HttpClient, Task<T>> requester, HttpClient client, int retries = 3, TimeSpan initialDelay = default)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have sworn we already had a function like this but I can't find it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was doing it wrong in another PR so i ended up not merging it.

{
var currentDelay = initialDelay == default ? TimeSpan.FromSeconds(30) : initialDelay;
for (int i = 0; i <= retries; i++)
{
try
{
return await requester(client);
}
catch (Exception)
{
if (i == retries)
{
throw;
}
await Task.Delay(currentDelay);
currentDelay *= 2;
}
}
throw new InvalidOperationException("Max retries reached.");
}

private Uri GetListeningUri(ITestOutputHelper output)
{
// Wait until the app is accepting HTTP requests
Expand Down Expand Up @@ -190,7 +212,7 @@ public Task AssertNotFound(string requestUrl)

internal Task<HttpResponseMessage> SendRequest(string path)
{
return _httpClient.GetAsync(new Uri(ListeningUri, path));
return RequestWithRetries(client => client.GetAsync(new Uri(ListeningUri, path)), _httpClient);
}

public async Task AssertStatusCode(string requestUrl, HttpStatusCode statusCode, string acceptContentType = null)
Expand All @@ -204,7 +226,7 @@ public async Task AssertStatusCode(string requestUrl, HttpStatusCode statusCode,
request.Headers.Add("Accept", acceptContentType);
}

var response = await _httpClient.SendAsync(request);
var response = await RequestWithRetries(client => client.SendAsync(request), _httpClient);
Assert.True(statusCode == response.StatusCode, $"Expected {requestUrl} to have status '{statusCode}' but it was '{response.StatusCode}'.");
}

Expand Down
16 changes: 9 additions & 7 deletions src/ProjectTemplates/test/MvcTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ public MvcTemplateTest(ProjectFactoryFixture projectFactory, ITestOutputHelper o
public ProjectFactoryFixture ProjectFactory { get; }
public ITestOutputHelper Output { get; }

[Theory]
[InlineData(null)]
[InlineData("F#", Skip = "https://github.com/aspnet/AspNetCore/issues/14022")]
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2267", FlakyOn.All)]
public async Task MvcTemplate_NoAuthImplAsync(string languageOverride)
[Fact(Skip = "https://github.com/aspnet/AspNetCore/issues/14022")]
public async Task MvcTemplate_NoAuthFSharp() => await MvcTemplateCore(languageOverride: "F#");

[Fact]
public async Task MvcTemplate_NoAuthCSharp() => await MvcTemplateCore(languageOverride: null);


private async Task MvcTemplateCore(string languageOverride)
{
Project = await ProjectFactory.GetOrCreateProject("mvcnoauth" + (languageOverride == "F#" ? "fsharp" : "csharp"), Output);

Expand Down Expand Up @@ -98,8 +101,7 @@ public async Task MvcTemplate_NoAuthImplAsync(string languageOverride)
[Theory]
[InlineData(true)]
[InlineData(false)]
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2267", FlakyOn.All)]
public async Task MvcTemplate_IndividualAuthImplAsync(bool useLocalDB)
public async Task MvcTemplate_IndividualAuth(bool useLocalDB)
{
Project = await ProjectFactory.GetOrCreateProject("mvcindividual" + (useLocalDB ? "uld" : ""), Output);

Expand Down
6 changes: 2 additions & 4 deletions src/ProjectTemplates/test/RazorPagesTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public RazorPagesTemplateTest(ProjectFactoryFixture projectFactory, ITestOutputH
public ITestOutputHelper Output { get; }

[Fact]
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2327", FlakyOn.All)]
public async Task RazorPagesTemplate_NoAuthImplAsync()
public async Task RazorPagesTemplate_NoAuth()
{
Project = await ProjectFactory.GetOrCreateProject("razorpagesnoauth", Output);

Expand Down Expand Up @@ -95,10 +94,9 @@ public async Task RazorPagesTemplate_NoAuthImplAsync()
}

[Theory]
[Flaky("https://github.com/aspnet/AspNetCore-Internal/issues/2335", FlakyOn.All)]
[InlineData(false)]
[InlineData(true)]
public async Task RazorPagesTemplate_IndividualAuthImplAsync(bool useLocalDB)
public async Task RazorPagesTemplate_IndividualAuth(bool useLocalDB)
{
Project = await ProjectFactory.GetOrCreateProject("razorpagesindividual" + (useLocalDB ? "uld" : ""), Output);

Expand Down
11 changes: 7 additions & 4 deletions src/ProjectTemplates/test/WebApiTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public WebApiTemplateTest(ProjectFactoryFixture factoryFixture, ITestOutputHelpe

public Project Project { get; set; }

[Theory]
[InlineData(null)]
[InlineData("F#")]
public async Task WebApiTemplateAsync(string languageOverride)
[Fact]
public async Task WebApiTemplateFSharp() => await WebApiTemplateCore(languageOverride: "F#");

[Fact]
public async Task WebApiTemplateCSharp() => await WebApiTemplateCore(languageOverride: null);

private async Task WebApiTemplateCore(string languageOverride)
{
Project = await FactoryFixture.GetOrCreateProject("webapi" + (languageOverride == "F#" ? "fsharp" : "csharp"), Output);

Expand Down