public void TestStress() { const int threadCount = 4; const int loops = 1000; var totalLoops = 0; var threads = new Thread[threadCount]; for (var i = 0; i < threadCount; i++) { (threads[i] = new Thread(context => { for (var j = 0; j < loops; j++) { var item = new TestObject(); AsyncDisposer.Enqueue(item); Interlocked.Increment(ref totalLoops); } })).Start(i); } foreach (var thread in threads) { thread.Join(); } Assert.AreEqual(threadCount * loops, totalLoops); Thread.Sleep(1000); Assert.AreEqual(threadCount * loops, TestObject.DisposedCount); }
public void TestEnqueueDisposable() { var obj = new TestObject(); AsyncDisposer.Enqueue(obj); Thread.Sleep(1000); Assert.IsTrue(obj.Disposed); }