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.
// 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.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing;
@ -16,6 +16,9 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
{
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)
{
}
@ -51,7 +54,15 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
await deployer.DeployAsync();
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);
@ -59,11 +70,12 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
output = output.Trim('\n');
Assert.Equal(output, "Application is shutting down...\n" +
"Stopping firing\n" +
"Stopping end\n" +
"Stopped firing\n" +
"Stopped end");
Assert.Equal("Application is shutting down...\n" +
"Stopping firing\n" +
"Stopping end\n" +
"Stopped firing\n" +
"Stopped end",
output);
}
}
}
@ -107,10 +119,11 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
output = output.Trim('\n');
Assert.Equal(output, "Stopping firing\n" +
"Stopping end\n" +
"Stopped firing\n" +
"Stopped end");
Assert.Equal("Stopping firing\n" +
"Stopping end\n" +
"Stopped firing\n" +
"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.
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
@ -15,6 +16,9 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
{
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)
{
}
@ -44,8 +48,7 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
RuntimeArchitecture.x64)
{
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = ApplicationType.Portable,
PublishApplicationBeforeDeployment = true
ApplicationType = ApplicationType.Portable
};
using (var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory))
@ -56,8 +59,13 @@ namespace Microsoft.AspNetCore.Hosting.FunctionalTests
var mre = new ManualResetEventSlim();
deployer.HostProcess.OutputDataReceived += (sender, args) =>
{
output += args.Data + '\n';
mre.Set();
if (!string.Equals(args.Data, ApplicationStartedMessage)
&& !string.IsNullOrEmpty(args.Data)
&& !NowListeningRegex.Match(args.Data).Success)
{
output += args.Data + '\n';
mre.Set();
}
};
mre.Wait(10000);