Allow at max one Remove operation to fail in tests.
[mono.git] / mcs / class / corlib / Test / System.Collections.Concurrent / CollectionStressTestHelper.cs
index 975bf773cb5c2816ab72cab41aeada1394578cb5..7e2cd9ef27d6f68e220a4b8cd259350cccacb218 100644 (file)
@@ -81,7 +81,7 @@ namespace MonoTests.System.Collections.Concurrent
                                const int delta = 5;
                                
                                for (int i = 0; i < (count + delta) * threads; i++)
-                                       coll.TryAdd (i);
+                                       while (!coll.TryAdd (i));
                                
                                bool state = true;
                                
@@ -91,8 +91,12 @@ namespace MonoTests.System.Collections.Concurrent
                                        bool s = true;
                                        int t;
                                        
-                                       for (int i = 0; i < count; i++)
+                                       for (int i = 0; i < count; i++) {
                                                s &= coll.TryTake (out t);
+                                               // try again in case it was a transient failure
+                                               if (!s && coll.TryTake (out t))
+                                                       s = true;
+                                       }
                                        
                                        if (!s)
                                                state = false;