From e53abdb2b8c95d71281f719b5967067191a7cc65 Mon Sep 17 00:00:00 2001 From: John Luo Date: Mon, 18 Sep 2017 17:00:18 -0700 Subject: [PATCH] Fix flaky hosting functional tests - Filter out startup messages - Do not publish test apps if not needed - Disable running functional tests in parallel --- .../Properties/AssemblyInfo.cs | 6 ++++ .../ShutdownTests.cs | 35 +++++++++++++------ .../WebHostBuilderTests.cs | 16 ++++++--- 3 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Hosting.FunctionalTests/Properties/AssemblyInfo.cs diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Properties/AssemblyInfo.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..a82d7bc1e5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Properties/AssemblyInfo.cs @@ -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)] diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs index b6b3d688d2..8aca0ef2d4 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/ShutdownTests.cs @@ -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: (?.*)$"); + 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); } } } diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/WebHostBuilderTests.cs index dbfe18d889..5f9e7894f3 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/WebHostBuilderTests.cs @@ -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: (?.*)$"); + 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);