From 0d98fbbe2907ca2cd4f2e68c938225b4f411d1bd Mon Sep 17 00:00:00 2001 From: Guillaume Pouillet Date: Tue, 7 Dec 2010 10:30:12 +0100 Subject: [PATCH] Fix bug in BlockingCollection.TryTake Add corresponding unit test --- .../BlockingCollection.cs | 1 + .../BlockingCollectionTests.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs b/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs index 75d7784cfbbb..56fcf1cb0ad2 100644 --- a/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs +++ b/mcs/class/System/System.Collections.Concurrent/BlockingCollection.cs @@ -269,6 +269,7 @@ bool TryTake (out T item, Func contFunc, CancellationToken token) if (!mreRemove.IsSet) mreRemove.Set (); + return true; } while (contFunc ()); return false; diff --git a/mcs/class/System/Test/System.Collections.Concurrent/BlockingCollectionTests.cs b/mcs/class/System/Test/System.Collections.Concurrent/BlockingCollectionTests.cs index c9a5829a530d..b88479f3d973 100644 --- a/mcs/class/System/Test/System.Collections.Concurrent/BlockingCollectionTests.cs +++ b/mcs/class/System/Test/System.Collections.Concurrent/BlockingCollectionTests.cs @@ -166,6 +166,22 @@ public void ConsumingEnumerableTestCase() } Assert.AreEqual(0, defaultCollection.Count, "#" + i); } + + [TestAttribute] + public void TryTakeTestCase () + { + defaultCollection.Add (1); + + int value = default (int); + bool firstTake = defaultCollection.TryTake (out value); + int value2 = default (int); + bool secondTake = defaultCollection.TryTake (out value2); + + Assert.AreEqual (1, value); + Assert.IsTrue (firstTake); + Assert.AreEqual (default (int), value2); + Assert.IsFalse (secondTake); + } } } #endif