diff options
author | Rodrigo Kumpera <kumpera@gmail.com> | 2013-05-30 23:42:51 +0400 |
---|---|---|
committer | Rodrigo Kumpera <kumpera@gmail.com> | 2013-05-30 23:43:25 +0400 |
commit | 9015a7f6097ad391a9c212966341ef488510d0b7 (patch) | |
tree | 6ca6a24526524add1058832fb3542d56b8cda71d /mcs | |
parent | dbbb5ff89b3cd03c1a5376d87272610c13626083 (diff) |
Improve the reliability and error reporting of the TPL Dataflow test suite.
Diffstat (limited to 'mcs')
3 files changed, 39 insertions, 23 deletions
diff --git a/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/ReceivingTest.cs b/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/ReceivingTest.cs index 034604af33b..6955048fe34 100644 --- a/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/ReceivingTest.cs +++ b/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/ReceivingTest.cs @@ -230,10 +230,17 @@ namespace MonoTests.System.Threading.Tasks.Dataflow { scheduler.ExecuteAll (); Assert.IsTrue (target.HasPostponed); - ((IDataflowBlock)source).Fault (new Exception ()); + var exception = new Exception (); + ((IDataflowBlock)source).Fault (exception); scheduler.ExecuteAll (); - Thread.Sleep (100); + + try { + source.Completion.Wait (1000); + Assert.Fail ("Task must be faulted"); + } catch (AggregateException ex) { + Assert.AreEqual (exception, ex.InnerException, "#9"); + } Assert.IsTrue (source.Completion.IsFaulted); int value; @@ -254,27 +261,33 @@ namespace MonoTests.System.Threading.Tasks.Dataflow { var target = new TestTargetBlock<int> { Postpone = true }; Assert.IsNotNull (source.LinkTo (target)); - Assert.IsTrue (source.Post (1)); - Assert.IsTrue (source.Post (2)); - Assert.IsTrue (source.Post (3)); - Thread.Sleep (500); - Assert.IsTrue (target.HasPostponed); + Assert.IsTrue (source.Post (1), "#1"); + Assert.IsTrue (source.Post (2), "#2"); + Assert.IsTrue (source.Post (3), "#3"); + target.PostponedEvent.Wait (1000); + Assert.IsTrue (target.HasPostponed, "#4"); - ((IDataflowBlock)source).Fault (new Exception ()); + var exception = new Exception (); + ((IDataflowBlock)source).Fault (exception); - Thread.Sleep (100); + source.Completion.Wait (1000); - Assert.IsFalse (source.Completion.IsFaulted); + Assert.IsFalse (source.Completion.IsFaulted, "#5"); int value; - Assert.IsTrue (target.RetryPostponed (out value)); - Assert.AreEqual (1, value); + Assert.IsTrue (target.RetryPostponed (out value), "#6"); + Assert.AreEqual (1, value, "#7"); evt.Set (); - Thread.Sleep (100); + try { + source.Completion.Wait (1000); + Assert.Fail ("Task must be faulted"); + } catch (AggregateException ex) { + Assert.AreEqual (exception, ex.InnerException, "#9"); + } - Assert.IsTrue (source.Completion.IsFaulted); - Assert.IsFalse (target.RetryPostponed (out value)); + Assert.IsTrue (source.Completion.IsFaulted, "#10"); + Assert.IsFalse (target.RetryPostponed (out value), "#11"); } [Test] @@ -382,6 +395,8 @@ namespace MonoTests.System.Threading.Tasks.Dataflow { public T DirectlyAccepted { get; private set; } + public ManualResetEventSlim PostponedEvent = new ManualResetEventSlim (); + public DataflowMessageStatus OfferMessage ( DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T> source, bool consumeToAccept) @@ -391,6 +406,7 @@ namespace MonoTests.System.Threading.Tasks.Dataflow { if (Postpone) { postponed = Tuple.Create (source, messageHeader); + PostponedEvent.Set (); return DataflowMessageStatus.Postponed; } diff --git a/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/TransformManyBlockTest.cs b/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/TransformManyBlockTest.cs index 1a0adfb45ab..9d6ece4f8fc 100644 --- a/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/TransformManyBlockTest.cs +++ b/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/TransformManyBlockTest.cs @@ -85,11 +85,11 @@ namespace MonoTests.System.Threading.Tasks.Dataflow { var action = new ActionBlock<int> (i => received = true); transformMany.LinkTo (action); - Assert.IsTrue (transformMany.Post (1)); + Assert.IsTrue (transformMany.Post (1), "#1"); transformMany.Complete (); - Assert.IsTrue (transformMany.Completion.Wait (100)); - Assert.IsFalse (received); + Assert.IsTrue (transformMany.Completion.Wait (100), "#2"); + Assert.IsFalse (received, "#3"); } [Test] diff --git a/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/WriteOnceBlockTest.cs b/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/WriteOnceBlockTest.cs index 1d59b64bd61..320df00fb9b 100644 --- a/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/WriteOnceBlockTest.cs +++ b/mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/WriteOnceBlockTest.cs @@ -55,13 +55,13 @@ namespace MonoTests.System.Threading.Tasks.Dataflow { block.LinkTo (action1); block.LinkTo (action2); - Assert.IsTrue (block.Post (42)); - Assert.IsFalse (block.Post (43)); + Assert.IsTrue (block.Post (42), "#1"); + Assert.IsFalse (block.Post (43), "#2"); - Assert.IsTrue (evt.Wait (100)); + Assert.IsTrue (evt.Wait (100), "#3"); - Assert.IsTrue (act1); - Assert.IsTrue (act2); + Assert.IsTrue (act1, "#4"); + Assert.IsTrue (act2, "#5"); } [Test] |