Skip to content

Commit

Permalink
Test that futures throw Exception through Result property when they a…
Browse files Browse the repository at this point in the history
…re Faulted
  • Loading branch information
garuma committed Jul 27, 2011
1 parent 8078626 commit 0ddabfc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mcs/class/corlib/Test/System.Threading.Tasks/FutureTests.cs
Expand Up @@ -84,6 +84,34 @@ public void NestedFutureTest ()
Assert.AreEqual (101, t3.Result);
Assert.AreEqual (101, t4.Result);
}

[Test]
public void FaultedFutureTest ()
{
var thrown = new ApplicationException ();
var f = Task<int>.Factory.StartNew (() => { throw thrown; return 42; });
AggregateException ex = null;
try {
f.Wait ();
} catch (AggregateException e) {
ex = e;
}

Assert.IsNotNull (ex);
Assert.AreEqual (thrown, ex.InnerException);
Assert.AreEqual (TaskStatus.Faulted, f.Status);

ex = null;
try {
var result = f.Result;
} catch (AggregateException e) {
ex = e;
}

Assert.IsNotNull (ex);
Assert.AreEqual (TaskStatus.Faulted, f.Status);
Assert.AreEqual (thrown, ex.InnerException);
}
}
}
#endif

0 comments on commit 0ddabfc

Please sign in to comment.