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

This commit is contained in:
Chris Ross 2019-02-05 16:18:12 -08:00 committed by GitHub
parent b21c09665e
commit 7bd5297cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 18 deletions

View File

@ -10,6 +10,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Xunit;
namespace Interop.FunctionalTests namespace Interop.FunctionalTests
{ {
@ -172,28 +173,55 @@ namespace Interop.FunctionalTests
public static async Task 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 tempFile = Path.GetTempPath() + Guid.NewGuid() + ".xml";
var processOptions = new ProcessStartInfo using (var process = new Process())
{ {
FileName = GetToolLocation(), process.StartInfo.FileName = GetToolLocation();
RedirectStandardOutput = true, process.StartInfo.RedirectStandardOutput = true;
Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout {TimeoutSeconds}" process.StartInfo.RedirectStandardError = true;
+ (https ? " --tls --insecure" : ""), process.StartInfo.Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout {TimeoutSeconds}"
WindowStyle = ProcessWindowStyle.Hidden, + (https ? " --tls --insecure" : "");
CreateNoWindow = true, process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
}; process.StartInfo.CreateNoWindow = true;
using (var process = Process.Start(processOptions)) process.OutputDataReceived += (_, args) =>
{
var dataTask = process.StandardOutput.ReadToEndAsync();
if (await Task.WhenAny(dataTask, Task.Delay(TimeSpan.FromSeconds(TimeoutSeconds * 2))) != dataTask)
{ {
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(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."); throw new TimeoutException($"h2spec didn't exit within {TimeoutSeconds * 2} seconds.");
} }
var data = await dataTask;
logger.LogDebug(data);
var results = File.ReadAllText(tempFile); var results = File.ReadAllText(tempFile);
File.Delete(tempFile); File.Delete(tempFile);
@ -229,4 +257,4 @@ namespace Interop.FunctionalTests
} }
} }
} }
} }

View File

@ -23,7 +23,7 @@ namespace Interop.FunctionalTests
SkipReason = "Missing Windows ALPN support: https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation#Support")] SkipReason = "Missing Windows ALPN support: https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation#Support")]
public class H2SpecTests : LoggedTest public class H2SpecTests : LoggedTest
{ {
[ConditionalTheory(Skip = "Skipped while debugging https://github.com/aspnet/AspNetCore-Internal/issues/1720")] [ConditionalTheory]
[MemberData(nameof(H2SpecTestCases))] [MemberData(nameof(H2SpecTestCases))]
public async Task RunIndividualTestCase(H2SpecTestCase testCase) public async Task RunIndividualTestCase(H2SpecTestCase testCase)
{ {