From 7bd5297cfa672c797e2fcbfffa6dc048699abd32 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 5 Feb 2019 16:18:12 -0800 Subject: [PATCH] Re-enable h2spec tests with more diagnostics Internal/#1720 (#7259) --- .../Interop.FunctionalTests/H2SpecCommands.cs | 62 ++++++++++++++----- .../Interop.FunctionalTests/H2SpecTests.cs | 2 +- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs index b3f4548865..56a46b3ad7 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs +++ b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs @@ -10,6 +10,7 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Xml; using Microsoft.Extensions.Logging; +using Xunit; namespace Interop.FunctionalTests { @@ -172,28 +173,55 @@ namespace Interop.FunctionalTests public static async Task RunTest(string testId, int port, bool https, ILogger logger) { var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".xml"; - var processOptions = new ProcessStartInfo + using (var process = new Process()) { - FileName = GetToolLocation(), - RedirectStandardOutput = true, - Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout {TimeoutSeconds}" - + (https ? " --tls --insecure" : ""), - WindowStyle = ProcessWindowStyle.Hidden, - CreateNoWindow = true, - }; + process.StartInfo.FileName = GetToolLocation(); + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout {TimeoutSeconds}" + + (https ? " --tls --insecure" : ""); + process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + process.StartInfo.CreateNoWindow = true; - using (var process = Process.Start(processOptions)) - { - var dataTask = process.StandardOutput.ReadToEndAsync(); - - if (await Task.WhenAny(dataTask, Task.Delay(TimeSpan.FromSeconds(TimeoutSeconds * 2))) != dataTask) + process.OutputDataReceived += (_, args) => { + if (!string.IsNullOrEmpty(args.Data)) + { + logger.LogDebug(args.Data); + } + }; + process.ErrorDataReceived += (_, args) => + { + if (!string.IsNullOrEmpty(args.Data)) + { + logger.LogError(args.Data); + } + }; + var exitedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + process.EnableRaisingEvents = true; // Enables Exited + process.Exited += (_, args) => + { + logger.LogDebug("H2spec has exited."); + exitedTcs.TrySetResult(0); + }; + + Assert.True(process.Start()); + process.BeginOutputReadLine(); // Starts OutputDataReceived + process.BeginErrorReadLine(); // Starts ErrorDataReceived + + if (await Task.WhenAny(exitedTcs.Task, Task.Delay(TimeSpan.FromSeconds(TimeoutSeconds * 2))) != exitedTcs.Task) + { + try + { + process.Kill(); + } + catch (Exception ex) + { + throw new TimeoutException($"h2spec didn't exit within {TimeoutSeconds * 2} seconds.", ex); + } throw new TimeoutException($"h2spec didn't exit within {TimeoutSeconds * 2} seconds."); } - var data = await dataTask; - logger.LogDebug(data); - var results = File.ReadAllText(tempFile); File.Delete(tempFile); @@ -229,4 +257,4 @@ namespace Interop.FunctionalTests } } } -} \ No newline at end of file +} diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs index 9145d7a027..361b4c0e50 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs +++ b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs @@ -23,7 +23,7 @@ namespace Interop.FunctionalTests SkipReason = "Missing Windows ALPN support: https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation#Support")] public class H2SpecTests : LoggedTest { - [ConditionalTheory(Skip = "Skipped while debugging https://github.com/aspnet/AspNetCore-Internal/issues/1720")] + [ConditionalTheory] [MemberData(nameof(H2SpecTestCases))] public async Task RunIndividualTestCase(H2SpecTestCase testCase) {