You've already forked linux-packaging-mono
Imported Upstream version 3.8.0
Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
@ -30,6 +30,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using NUnit.Framework;
|
||||
using MonoTests.System.Threading.Tasks;
|
||||
|
||||
namespace MonoTests.System.Collections.Concurrent
|
||||
{
|
||||
@ -115,6 +116,34 @@ namespace MonoTests.System.Collections.Concurrent
|
||||
CollectionStressTestHelper.RemoveStressTest (new ConcurrentQueue<int> (), CheckOrderingType.InOrder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StressTryPeekTestCase ()
|
||||
{
|
||||
ParallelTestHelper.Repeat (delegate {
|
||||
var queue = new ConcurrentQueue<object> ();
|
||||
queue.Enqueue (new object());
|
||||
|
||||
const int threads = 10;
|
||||
int threadCounter = 0;
|
||||
bool success = true;
|
||||
|
||||
ParallelTestHelper.ParallelStressTest (queue, (q) => {
|
||||
int threadId = Interlocked.Increment (ref threadCounter);
|
||||
object temp;
|
||||
if (threadId < threads)
|
||||
{
|
||||
while (queue.TryPeek (out temp))
|
||||
if (temp == null)
|
||||
success = false;
|
||||
} else {
|
||||
queue.TryDequeue (out temp);
|
||||
}
|
||||
}, threads);
|
||||
|
||||
Assert.IsTrue (success, "TryPeek returned unexpected null value.");
|
||||
}, 10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountTestCase()
|
||||
{
|
||||
@ -215,6 +244,30 @@ namespace MonoTests.System.Collections.Concurrent
|
||||
{
|
||||
queue.CopyTo (new int[3], 0);
|
||||
}
|
||||
|
||||
static WeakReference CreateWeakReference (object obj)
|
||||
{
|
||||
return new WeakReference (obj);
|
||||
}
|
||||
|
||||
[Test]
|
||||
// This depends on precise stack scanning
|
||||
[Category ("NotWorking")]
|
||||
public void TryDequeueReferenceTest ()
|
||||
{
|
||||
var obj = new Object ();
|
||||
var weakReference = CreateWeakReference(obj);
|
||||
var queue = new ConcurrentQueue<object> ();
|
||||
|
||||
queue.Enqueue (obj);
|
||||
queue.TryDequeue (out obj);
|
||||
obj = null;
|
||||
|
||||
GC.Collect ();
|
||||
GC.WaitForPendingFinalizers ();
|
||||
|
||||
Assert.IsFalse (weakReference.IsAlive);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user