Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.Extensions.Logging;

namespace Interop.FunctionalTests
{
public static class H2SpecCommands
{
private const int TimeoutSeconds = 15;

private static string GetToolLocation()
{
var root = Path.Combine(Environment.CurrentDirectory, "h2spec");
Expand Down Expand Up @@ -166,22 +169,29 @@ 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,
};

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down