Skip to content

Commit 6a5c0cf

Browse files
authored
Manually time out H2SpecTests (#6366)
1 parent 236ceb7 commit 6a5c0cf

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecCommands.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
using System.Globalization;
88
using System.IO;
99
using System.Runtime.InteropServices;
10+
using System.Threading.Tasks;
1011
using System.Xml;
1112
using Microsoft.Extensions.Logging;
1213

1314
namespace Interop.FunctionalTests
1415
{
1516
public static class H2SpecCommands
1617
{
18+
private const int TimeoutSeconds = 15;
19+
1720
private static string GetToolLocation()
1821
{
1922
var root = Path.Combine(Environment.CurrentDirectory, "h2spec");
@@ -166,22 +169,29 @@ private static bool IsTestLine(string line, out string testNumber, out string de
166169
return false;
167170
}
168171

169-
public static void RunTest(string testId, int port, bool https, ILogger logger)
172+
public static async Task RunTest(string testId, int port, bool https, ILogger logger)
170173
{
171174
var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".xml";
172175
var processOptions = new ProcessStartInfo
173176
{
174177
FileName = GetToolLocation(),
175178
RedirectStandardOutput = true,
176-
Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout 15"
179+
Arguments = $"{testId} -p {port.ToString(CultureInfo.InvariantCulture)} --strict -j {tempFile} --timeout {TimeoutSeconds}"
177180
+ (https ? " --tls --insecure" : ""),
178181
WindowStyle = ProcessWindowStyle.Hidden,
179182
CreateNoWindow = true,
180183
};
181184

182185
using (var process = Process.Start(processOptions))
183186
{
184-
var data = process.StandardOutput.ReadToEnd();
187+
var dataTask = process.StandardOutput.ReadToEndAsync();
188+
189+
if (await Task.WhenAny(dataTask, Task.Delay(TimeSpan.FromSeconds(TimeoutSeconds * 2))) != dataTask)
190+
{
191+
throw new TimeoutException($"h2spec didn't exit within {TimeoutSeconds * 2} seconds.");
192+
}
193+
194+
var data = await dataTask;
185195
logger.LogDebug(data);
186196

187197
var results = File.ReadAllText(tempFile);

src/Servers/Kestrel/test/Interop.FunctionalTests/H2SpecTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task RunIndividualTestCase(H2SpecTestCase testCase)
4646
{
4747
await host.StartAsync();
4848

49-
H2SpecCommands.RunTest(testCase.Id, host.GetPort(), testCase.Https, Logger);
49+
await H2SpecCommands.RunTest(testCase.Id, host.GetPort(), testCase.Https, Logger);
5050

5151
await host.StopAsync();
5252
}

0 commit comments

Comments
 (0)