|
7 | 7 | using System.Globalization; |
8 | 8 | using System.IO; |
9 | 9 | using System.Runtime.InteropServices; |
| 10 | +using System.Threading.Tasks; |
10 | 11 | using System.Xml; |
11 | 12 | using Microsoft.Extensions.Logging; |
12 | 13 |
|
13 | 14 | namespace Interop.FunctionalTests |
14 | 15 | { |
15 | 16 | public static class H2SpecCommands |
16 | 17 | { |
| 18 | + private const int TimeoutSeconds = 15; |
| 19 | + |
17 | 20 | private static string GetToolLocation() |
18 | 21 | { |
19 | 22 | var root = Path.Combine(Environment.CurrentDirectory, "h2spec"); |
@@ -166,22 +169,29 @@ private static bool IsTestLine(string line, out string testNumber, out string de |
166 | 169 | return false; |
167 | 170 | } |
168 | 171 |
|
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) |
170 | 173 | { |
171 | 174 | var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".xml"; |
172 | 175 | var processOptions = new ProcessStartInfo |
173 | 176 | { |
174 | 177 | FileName = GetToolLocation(), |
175 | 178 | 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}" |
177 | 180 | + (https ? " --tls --insecure" : ""), |
178 | 181 | WindowStyle = ProcessWindowStyle.Hidden, |
179 | 182 | CreateNoWindow = true, |
180 | 183 | }; |
181 | 184 |
|
182 | 185 | using (var process = Process.Start(processOptions)) |
183 | 186 | { |
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; |
185 | 195 | logger.LogDebug(data); |
186 | 196 |
|
187 | 197 | var results = File.ReadAllText(tempFile); |
|
0 commit comments