Fix flaky hosting functional tests

- Filter out startup messages
- Do not publish test apps if not needed
- Disable running functional tests in parallel
This commit is contained in:
John Luo 2017-09-18 17:00:18 -07:00 committed by =
parent 37e122a0c6
commit e53abdb2b8
3 changed files with 42 additions and 15 deletions

View File

@ -0,0 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Xunit;
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
@ -16,6 +16,9 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
{ {
public class ShutdownTests : LoggedTest public class ShutdownTests : LoggedTest
{ {
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$");
private const string ApplicationStartedMessage = "Application started. Press Ctrl+C to shut down.";
public ShutdownTests(ITestOutputHelper output) : base(output) public ShutdownTests(ITestOutputHelper output) : base(output)
{ {
} }
@ -51,7 +54,15 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
await deployer.DeployAsync(); await deployer.DeployAsync();
string output = string.Empty; string output = string.Empty;
deployer.HostProcess.OutputDataReceived += (sender, args) => output += args.Data + '\n'; deployer.HostProcess.OutputDataReceived += (sender, args) =>
{
if (!string.Equals(args.Data, ApplicationStartedMessage)
&& !string.IsNullOrEmpty(args.Data)
&& !NowListeningRegex.Match(args.Data).Success)
{
output += args.Data + '\n';
}
};
SendSIGINT(deployer.HostProcess.Id); SendSIGINT(deployer.HostProcess.Id);
@ -59,11 +70,12 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
output = output.Trim('\n'); output = output.Trim('\n');
Assert.Equal(output, "Application is shutting down...\n" + Assert.Equal("Application is shutting down...\n" +
"Stopping firing\n" + "Stopping firing\n" +
"Stopping end\n" + "Stopping end\n" +
"Stopped firing\n" + "Stopped firing\n" +
"Stopped end"); "Stopped end",
output);
} }
} }
} }
@ -107,10 +119,11 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
output = output.Trim('\n'); output = output.Trim('\n');
Assert.Equal(output, "Stopping firing\n" + Assert.Equal("Stopping firing\n" +
"Stopping end\n" + "Stopping end\n" +
"Stopped firing\n" + "Stopped firing\n" +
"Stopped end"); "Stopped end",
output);
} }
} }
} }

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO; using System.IO;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
@ -15,6 +16,9 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
{ {
public class WebHostBuilderTests : LoggedTest public class WebHostBuilderTests : LoggedTest
{ {
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$");
private const string ApplicationStartedMessage = "Application started. Press Ctrl+C to shut down.";
public WebHostBuilderTests(ITestOutputHelper output) : base(output) public WebHostBuilderTests(ITestOutputHelper output) : base(output)
{ {
} }
@ -44,8 +48,7 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
RuntimeArchitecture.x64) RuntimeArchitecture.x64)
{ {
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0", TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = ApplicationType.Portable, ApplicationType = ApplicationType.Portable
PublishApplicationBeforeDeployment = true
}; };
using (var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory)) using (var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory))
@ -56,8 +59,13 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
var mre = new ManualResetEventSlim(); var mre = new ManualResetEventSlim();
deployer.HostProcess.OutputDataReceived += (sender, args) => deployer.HostProcess.OutputDataReceived += (sender, args) =>
{ {
output += args.Data + '\n'; if (!string.Equals(args.Data, ApplicationStartedMessage)
mre.Set(); && !string.IsNullOrEmpty(args.Data)
&& !NowListeningRegex.Match(args.Data).Success)
{
output += args.Data + '\n';
mre.Set();
}
}; };
mre.Wait(10000); mre.Wait(10000);