Skip to content

Commit 9aa730e

Browse files
committed
1.0.2: fixed bug where timeouts would suppress throwOnError errors
1 parent 93fd889 commit 9aa730e

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

MedallionShell.Tests/GeneralTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Reflection;
78
using System.Text;
89
using System.Threading;
910
using System.Threading.Tasks;
@@ -121,6 +122,15 @@ public void TestExitCode()
121122
shell.Run("SampleCommand", "exit", 0).Task.Wait();
122123
}
123124

125+
[TestMethod]
126+
public void TestThrowOnErrorWithTimeout()
127+
{
128+
var command = Command.Run("SampleCommand", new object[] { "exit", 1 }, o => o.ThrowOnError().Timeout(TimeSpan.FromDays(1)));
129+
var ex = UnitTestHelpers.AssertThrows<AggregateException>(() => command.Task.Wait());
130+
ex.InnerExceptions.Select(e => e.GetType()).SequenceEqual(new[] { typeof(ErrorExitCodeException) })
131+
.ShouldEqual(true);
132+
}
133+
124134
[TestMethod]
125135
public void TestTimeout()
126136
{
@@ -219,6 +229,15 @@ public void TestNestedKill()
219229
UnitTestHelpers.AssertThrows<ArgumentOutOfRangeException>(() => lines[0].ShouldEqual("a line"));
220230
}
221231

232+
[TestMethod]
233+
public void TestVersioning()
234+
{
235+
var version = typeof(Command).Assembly.GetName().Version.ToString();
236+
var informationalVersion = (AssemblyInformationalVersionAttribute)typeof(Command).Assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute));
237+
Assert.IsNotNull(informationalVersion);
238+
version.ShouldEqual(informationalVersion.InformationalVersion + ".0");
239+
}
240+
222241
private IEnumerable<string> ErrorLines()
223242
{
224243
yield return "1";

MedallionShell/MedallionShell.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
A lightweight library that simplifies working with processes in .NET
1616
</description>
1717
<releaseNotes>
18-
Allowed for argument ommission in Command.Run(), other minor fixes
18+
Fixed bug where timeout would suppress errors from ThrowOnError option
1919
</releaseNotes>
2020
<copyright>Copyright 2014</copyright>
2121
<tags>process async</tags>

MedallionShell/ProcessCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,16 @@ private static Task CreateProcessTask(Process process, bool throwOnError, TimeSp
147147
}
148148

149149
private static async Task AddTimeout(Task task, Process process, TimeSpan timeout)
150-
{
150+
{
151+
// wait for either the given task or the timeout to complete
151152
// http://stackoverflow.com/questions/4238345/asynchronously-wait-for-taskt-to-complete-with-timeout
152-
if (await SystemTask.WhenAny(task, SystemTask.Delay(timeout)).ConfigureAwait(false) != task)
153+
var completed = await SystemTask.WhenAny(task, SystemTask.Delay(timeout)).ConfigureAwait(false);
154+
155+
// Task.WhenAny() swallows errors: wait for the completed task to propagate any errors that occurred
156+
await completed.ConfigureAwait(false);
157+
158+
// if we timed out, kill the process
159+
if (completed != task)
153160
{
154161
Log.WriteLine("Process timed out");
155162
TryKillProcess(process);

MedallionShell/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535

36+
// 1.0.2: fixed bug where timeout would suppress errors from ThrowOnError option
3637
// 1.0.1.0: allowed for argument ommission in Command.Run(), other minor fixes
37-
[assembly: AssemblyVersion("1.0.1.0")]
38+
[assembly: AssemblyInformationalVersion("1.0.2")]
39+
[assembly: AssemblyVersion("1.0.2.0")]
3840
[assembly: AssemblyFileVersion("1.0.0.0")]
3941

4042
[assembly: InternalsVisibleTo("MedallionShell.Tests")]

0 commit comments

Comments
 (0)