diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs index 0286f571f71b..b3f4548865cf 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs +++ b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs @@ -7,6 +7,7 @@ using System.Globalization; using System.IO; using System.Runtime.InteropServices; +using System.Threading.Tasks; using System.Xml; using Microsoft.Extensions.Logging; @@ -14,6 +15,8 @@ namespace Interop.FunctionalTests { public static class H2SpecCommands { + private const int TimeoutSeconds = 15; + private static string GetToolLocation() { var root = Path.Combine(Environment.CurrentDirectory, "h2spec"); @@ -166,14 +169,14 @@ private static bool IsTestLine(string line, out string testNumber, out string de return false; } - public static void RunTest(string testId, int port, bool https, ILogger logger) + public static async Task RunTest(string testId, int port, bool https, ILogger logger) { var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".xml"; var processOptions = new ProcessStartInfo { FileName = GetToolLocation(), RedirectStandardOutput = true, - Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout 15" + Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout {TimeoutSeconds}" + (https ? " --tls --insecure" : ""), WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, @@ -181,7 +184,14 @@ public static void RunTest(string testId, int port, bool https, ILogger logger) using (var process = Process.Start(processOptions)) { - var data = process.StandardOutput.ReadToEnd(); + var dataTask = process.StandardOutput.ReadToEndAsync(); + + if (await Task.WhenAny(dataTask, Task.Delay(TimeSpan.FromSeconds(TimeoutSeconds * 2))) != dataTask) + { + throw new TimeoutException($"h2spec didn't exit within {TimeoutSeconds * 2} seconds."); + } + + var data = await dataTask; logger.LogDebug(data); var results = File.ReadAllText(tempFile); diff --git a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs index f0c3b3de0061..361b4c0e50b9 100644 --- a/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs +++ b/src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs @@ -46,7 +46,7 @@ public async Task RunIndividualTestCase(H2SpecTestCase testCase) { await host.StartAsync(); - H2SpecCommands.RunTest(testCase.Id, host.GetPort(), testCase.Https, Logger); + await H2SpecCommands.RunTest(testCase.Id, host.GetPort(), testCase.Https, Logger); await host.StopAsync(); }