Skip to content

Commit

Permalink
Same test for TaskCompletionSource
Browse files Browse the repository at this point in the history
  • Loading branch information
garuma committed Jul 27, 2011
1 parent 7d088a3 commit 06cd95e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mcs/class/corlib/Test/System.Threading.Tasks/FutureTests.cs
Expand Up @@ -99,6 +99,7 @@ public void FaultedFutureTest ()

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

ex = null;
Expand All @@ -110,6 +111,7 @@ public void FaultedFutureTest ()

Assert.IsNotNull (ex);
Assert.AreEqual (TaskStatus.Faulted, f.Status);
Assert.AreEqual (thrown, f.Exception.InnerException);
Assert.AreEqual (thrown, ex.InnerException);
}
}
Expand Down
Expand Up @@ -120,6 +120,38 @@ public void ContinuationTest ()
Assert.AreEqual (TaskStatus.RanToCompletion, t.Status, "#2");
Assert.IsTrue (result);
}

[Test]
public void FaultedFutureTest ()
{
var thrown = new ApplicationException ();
var source = new TaskCompletionSource<int> ();
source.TrySetException (thrown);
var f = source.Task;
AggregateException ex = null;
try {
f.Wait ();
} catch (AggregateException e) {
ex = e;
}

Assert.IsNotNull (ex);
Assert.AreEqual (thrown, ex.InnerException);
Assert.AreEqual (thrown, f.Exception.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, f.Exception.InnerException);
Assert.AreEqual (thrown, ex.InnerException);
}
}
}
#endif

0 comments on commit 06cd95e

Please sign in to comment.