Skip to content

Commit 20f6d65

Browse files
author
John Luo
authored
Fix flakiness/timeout in gRPC template tests (#19982)
Do not search for port number for cases where we are testing for failure.
1 parent 2e2a82d commit 20f6d65

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

src/ProjectTemplates/test/GrpcTemplateTest.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Reflection;
56
using System.Runtime.InteropServices;
67
using System.Threading.Tasks;
78
using Microsoft.AspNetCore.Testing;
@@ -24,11 +25,16 @@ public GrpcTemplateTest(ProjectFactoryFixture projectFactory, ITestOutputHelper
2425
public ProjectFactoryFixture ProjectFactory { get; }
2526
public ITestOutputHelper Output { get; }
2627

27-
[ConditionalFact(Skip = "This test run for over an hour")]
28+
[ConditionalFact]
2829
[SkipOnHelix("Not supported queues", Queues = "Windows.7.Amd64;Windows.7.Amd64.Open;OSX.1014.Amd64;OSX.1014.Amd64.Open")]
2930
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/19716")]
3031
public async Task GrpcTemplate()
3132
{
33+
// Setup AssemblyTestLog
34+
var assemblyLog = AssemblyTestLog.Create(Assembly.GetExecutingAssembly(), baseDirectory: Project.ArtifactsLogDir);
35+
using var testLog = assemblyLog.StartTestLog(Output, nameof(GrpcTemplateTest), out var loggerFactory);
36+
var logger = loggerFactory.CreateLogger("TestLogger");
37+
3238
Project = await ProjectFactory.GetOrCreateProject("grpc", Output);
3339

3440
var createResult = await Project.RunDotNetNewAsync("grpc");
@@ -40,18 +46,24 @@ public async Task GrpcTemplate()
4046
var buildResult = await Project.RunDotNetBuildAsync();
4147
Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", Project, buildResult));
4248

43-
using (var serverProcess = Project.StartBuiltProjectAsync())
49+
var isOsx = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
50+
var isWindowsOld = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version < new Version(6, 2);
51+
var unsupported = isOsx || isWindowsOld;
52+
53+
using (var serverProcess = Project.StartBuiltProjectAsync(hasListeningUri: !unsupported, logger: logger))
4454
{
4555
// These templates are HTTPS + HTTP/2 only which is not supported on Mac due to missing ALPN support.
4656
// https://github.com/dotnet/aspnetcore/issues/11061
47-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
57+
if (isOsx)
4858
{
59+
serverProcess.Process.WaitForExit(assertSuccess: false);
4960
Assert.True(serverProcess.Process.HasExited, "built");
5061
Assert.Contains("System.NotSupportedException: HTTP/2 over TLS is not supported on macOS due to missing ALPN support.",
5162
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built service", Project, serverProcess.Process));
5263
}
53-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version < new Version(6, 2))
64+
else if (isWindowsOld)
5465
{
66+
serverProcess.Process.WaitForExit(assertSuccess: false);
5567
Assert.True(serverProcess.Process.HasExited, "built");
5668
Assert.Contains("System.NotSupportedException: HTTP/2 over TLS is not supported on Windows 7 due to missing ALPN support.",
5769
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built service", Project, serverProcess.Process));
@@ -64,18 +76,20 @@ public async Task GrpcTemplate()
6476
}
6577
}
6678

67-
using (var aspNetProcess = Project.StartPublishedProjectAsync())
79+
using (var aspNetProcess = Project.StartPublishedProjectAsync(hasListeningUri: !unsupported))
6880
{
6981
// These templates are HTTPS + HTTP/2 only which is not supported on Mac due to missing ALPN support.
7082
// https://github.com/dotnet/aspnetcore/issues/11061
71-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
83+
if (isOsx)
7284
{
85+
aspNetProcess.Process.WaitForExit(assertSuccess: false);
7386
Assert.True(aspNetProcess.Process.HasExited, "published");
7487
Assert.Contains("System.NotSupportedException: HTTP/2 over TLS is not supported on macOS due to missing ALPN support.",
7588
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published service", Project, aspNetProcess.Process));
7689
}
77-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version < new Version(6, 2))
90+
else if (isWindowsOld)
7891
{
92+
aspNetProcess.Process.WaitForExit(assertSuccess: false);
7993
Assert.True(aspNetProcess.Process.HasExited, "published");
8094
Assert.Contains("System.NotSupportedException: HTTP/2 over TLS is not supported on Windows 7 due to missing ALPN support.",
8195
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published service", Project, aspNetProcess.Process));

src/ProjectTemplates/test/Helpers/AspNetProcess.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.AspNetCore.Internal;
1515
using Microsoft.AspNetCore.Server.IntegrationTesting;
1616
using Microsoft.Extensions.CommandLineUtils;
17+
using Microsoft.Extensions.Logging;
1718
using Microsoft.Extensions.Logging.Abstractions;
1819
using OpenQA.Selenium;
1920
using OpenQA.Selenium.Edge;
@@ -38,7 +39,8 @@ public AspNetProcess(
3839
string dllPath,
3940
IDictionary<string, string> environmentVariables,
4041
bool published = true,
41-
bool hasListeningUri = true)
42+
bool hasListeningUri = true,
43+
ILogger logger = null)
4244
{
4345
_output = output;
4446
_httpClient = new HttpClient(new HttpClientHandler()
@@ -57,10 +59,18 @@ public AspNetProcess(
5759
output.WriteLine("Running ASP.NET application...");
5860

5961
var arguments = published ? $"exec {dllPath}" : "run";
62+
63+
logger?.LogInformation($"AspNetProcess - process: {DotNetMuxer.MuxerPathOrDefault()} arguments: {arguments}");
64+
6065
Process = ProcessEx.Run(output, workingDirectory, DotNetMuxer.MuxerPathOrDefault(), arguments, envVars: environmentVariables);
66+
67+
logger?.LogInformation("AspNetProcess - process started");
68+
6169
if (hasListeningUri)
6270
{
71+
logger?.LogInformation("AspNetProcess - Getting listening uri");
6372
ListeningUri = GetListeningUri(output) ?? throw new InvalidOperationException("Couldn't find the listening URL.");
73+
logger?.LogInformation($"AspNetProcess - Got {ListeningUri.ToString()}");
6474
}
6575
}
6676

src/ProjectTemplates/test/Helpers/Project.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Threading.Tasks;
1313
using Microsoft.AspNetCore.Internal;
1414
using Microsoft.Extensions.CommandLineUtils;
15+
using Microsoft.Extensions.Logging;
1516
using Xunit;
1617
using Xunit.Abstractions;
1718
using Xunit.Sdk;
@@ -207,7 +208,7 @@ internal AspNetProcess StartPublishedClientAsync()
207208
return new AspNetProcess(Output, TemplateClientReleaseDir, projectDll, environment);
208209
}
209210

210-
internal AspNetProcess StartBuiltProjectAsync(bool hasListeningUri = true)
211+
internal AspNetProcess StartBuiltProjectAsync(bool hasListeningUri = true, ILogger logger = null)
211212
{
212213
var environment = new Dictionary<string, string>
213214
{
@@ -220,7 +221,7 @@ internal AspNetProcess StartBuiltProjectAsync(bool hasListeningUri = true)
220221
};
221222

222223
var projectDll = Path.Combine(TemplateBuildDir, $"{ProjectName}.dll");
223-
return new AspNetProcess(Output, TemplateOutputDir, projectDll, environment, hasListeningUri: hasListeningUri);
224+
return new AspNetProcess(Output, TemplateOutputDir, projectDll, environment, hasListeningUri: hasListeningUri, logger: logger);
224225
}
225226

226227
internal AspNetProcess StartPublishedProjectAsync(bool hasListeningUri = true)

src/ProjectTemplates/test/ProjectTemplates.Tests.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<ProjectReference Include="../Web.Spa.ProjectTemplates/Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj" ReferenceOutputAssembly="false" />
5353
</ItemGroup>
5454

55+
<PropertyGroup>
56+
<PreserveExistingLogsInOutput Condition="'$(PreserveExistingLogsInOutput)' == '' AND '$(ContinuousIntegrationBuild)' == 'true'">true</PreserveExistingLogsInOutput>
57+
<PreserveExistingLogsInOutput Condition="'$(PreserveExistingLogsInOutput)' == ''">false</PreserveExistingLogsInOutput>
58+
</PropertyGroup>
59+
5560
<ItemGroup>
5661
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
5762
<_Parameter1>DotNetEfFullPath</_Parameter1>
@@ -69,6 +74,11 @@
6974
<_Parameter1>ContinuousIntegrationBuild</_Parameter1>
7075
<_Parameter2>true</_Parameter2>
7176
</AssemblyAttribute>
77+
<AssemblyAttribute Include="Microsoft.AspNetCore.Testing.TestFrameworkFileLoggerAttribute">
78+
<_Parameter1>$(PreserveExistingLogsInOutput)</_Parameter1>
79+
<_Parameter2>$(TargetFramework)</_Parameter2>
80+
<_Parameter3></_Parameter3>
81+
</AssemblyAttribute>
7282
</ItemGroup>
7383

7484
<Target Name="PrepareForTest" BeforeTargets="CoreCompile" Condition="$(DesignTimeBuild) != true">

0 commit comments

Comments
 (0)