Browse Source

Re-enable h2spec tests with more diagnostics Internal/#1720 (#7259)

Chris Ross 7 years ago
parent
commit
7bd5297cfa

+ 44 - 16
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();
+                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<int>(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(dataTask, Task.Delay(TimeSpan.FromSeconds(TimeoutSeconds * 2))) != dataTask)
+                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
             }
         }
     }
-}
+}

+ 1 - 1
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)
         {