[corlib] Add timeout to more tests
authorMarek Safar <marek.safar@gmail.com>
Thu, 12 Feb 2015 13:20:53 +0000 (14:20 +0100)
committerMarek Safar <marek.safar@gmail.com>
Thu, 12 Feb 2015 13:21:24 +0000 (14:21 +0100)
mcs/class/corlib/Test/System.Runtime.CompilerServices/AsyncTaskMethodBuilderTest.cs
mcs/class/corlib/Test/System/LazyTest.cs

index 2a6165aff571894f6abd8bdb28d76605833de88c..d6216f73dbed3d1a26ce7cf339341c0c40f73f3d 100644 (file)
@@ -26,8 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_4_5
-
 using System;
 using System.Threading;
 using System.Threading.Tasks;
@@ -40,12 +38,15 @@ namespace MonoTests.System.Runtime.CompilerServices
        [TestFixture]
        public class AsyncTaskMethodBuilderTest
        {
+#if !MONOTOUCH
+               // For some reason MT excludes CallContext handling
+
                [Test]
                public void CallContextFlow ()
                {
                        CallContext.LogicalSetData ("name0", "0");
 
-                       Task.WhenAll (Work ("A"), Work ("B")).Wait ();
+                       Assert.IsTrue (Task.WhenAll (Work ("A"), Work ("B")).Wait (4000), "#0");
                        Assert.IsNull (CallContext.LogicalGetData ("A"), "#A");
                        Assert.IsNull (CallContext.LogicalGetData ("B"), "#B");
                }
@@ -60,7 +61,6 @@ namespace MonoTests.System.Runtime.CompilerServices
                        var found = CallContext.LogicalGetData ("name");
                        Assert.AreEqual (name, found, "#2" + name);
                }
+#endif
        }
 }
-
-#endif
\ No newline at end of file
index 6fb77f4d0fe0105c6296ee86666a626a7ff01598..ce75180cb1b31e8c2bbc3887625a060566463b2a 100644 (file)
@@ -26,8 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_4_0
-
 using System;
 using System.Reflection;
 using System.Threading;
@@ -113,26 +111,32 @@ namespace MonoTests.System
                static int counter;
 
                [Test]
-               public void EnsureSingleThreadSafeExecution () {
+               public void EnsureSingleThreadSafeExecution ()
+               {
                        counter = 42;
 
                        var l = new Lazy<int> (delegate () { return counter ++; }, true);
-
+                       bool failed = false;
                        object monitor = new object ();
-                       var threads = new Thread [10];
-                       for (int i = 0; i < 10; ++i) {
+                       var threads = new Thread [4];
+                       for (int i = 0; i < threads.Length; ++i) {
                                threads [i] = new Thread (delegate () {
                                                lock (monitor) {
-                                                       Monitor.Wait (monitor);
+                                                       if (!Monitor.Wait (monitor, 2000))
+                                                               failed = true;
                                                }
                                                int val = l.Value;
                                        });
                        }
-                       for (int i = 0; i < 10; ++i)
+                       for (int i = 0; i < threads.Length; ++i)
                                threads [i].Start ();
                        lock (monitor)
                                Monitor.PulseAll (monitor);
-                       
+
+                       for (int i = 0; i < threads.Length; ++i)
+                               threads [i].Join ();
+
+                       Assert.IsFalse (failed);
                        Assert.AreEqual (42, l.Value);
                }
                
@@ -315,5 +319,3 @@ namespace MonoTests.System
 
        }
 }
-
-#endif