diff options
author | Pat Gavlin <pagavlin@microsoft.com> | 2017-03-14 10:05:26 -0700 |
---|---|---|
committer | Pat Gavlin <pagavlin@microsoft.com> | 2017-03-14 10:25:14 -0700 |
commit | bd7a88958776655867a4af3184dfef317f33839d (patch) | |
tree | d3a4cf5fe091fbde5eedfa4c2fd9485e4fa37c02 /tests/src/Common/Coreclr.TestWrapper | |
parent | c52a9f7a3019d408cd03aef9e5fb33263cb047ba (diff) | |
download | coreclr-bd7a88958776655867a4af3184dfef317f33839d.tar.gz coreclr-bd7a88958776655867a4af3184dfef317f33839d.tar.bz2 coreclr-bd7a88958776655867a4af3184dfef317f33839d.zip |
Do not wait on std{out,err} when a test times out.
The test wrapper currently waits on each of the process, stdout copy,
and stderr copy in turn. This makes it difficult to determine whether
or not the test did in fact time out, as the time in which it may
write to its output streams is effectively twice or thrice the
time used to determine success or failure (i.e. the process wait
timeout). This can cause situations like what we've seen in #10076,
where the harness reports that the process timed out but the test's
output indicates a successful run.
This change only waits on stdout/stderr if the process completes within
the time allotted; otherwise it cancels the copies and promptly reports
the timeout.
Diffstat (limited to 'tests/src/Common/Coreclr.TestWrapper')
-rw-r--r-- | tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs b/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs index ddb905087b..5c04827fca 100644 --- a/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs +++ b/tests/src/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs @@ -71,23 +71,27 @@ namespace CoreclrTestLib process.Start(); - Task copyOutput = process.StandardOutput.BaseStream.CopyToAsync(outputStream); - Task copyError = process.StandardError.BaseStream.CopyToAsync(errorStream); + var cts = new CancellationTokenSource(); + Task copyOutput = process.StandardOutput.BaseStream.CopyToAsync(outputStream, 4096, cts.Token); + Task copyError = process.StandardError.BaseStream.CopyToAsync(errorStream, 4096, cts.Token); - bool completed = process.WaitForExit(timeout); - copyOutput.Wait(timeout); - copyError.Wait(timeout); - - if (completed) + if (process.WaitForExit(timeout)) { // Process completed. Check process.ExitCode here. exitCode = process.ExitCode; + Task.WaitAll(copyOutput, copyError); } else { // Timed out. - outputWriter.WriteLine("cmdLine:" + executable + " Timed Out"); - errorWriter.WriteLine("cmdLine:" + executable + " Timed Out"); + try + { + cts.Cancel(); + } + catch {} + + outputWriter.WriteLine("\ncmdLine:" + executable + " Timed Out"); + errorWriter.WriteLine("\ncmdLine:" + executable + " Timed Out"); } outputWriter.WriteLine("Test Harness Exitcode is : " + exitCode.ToString()); |