public void PoolFlushTimout() { var pool = new ThirdPartyPool(0, 2); pool.FlushTimeOut = 1; var insance1 = pool.TakeInstance(); var insance2 = pool.TakeInstance(); // вернули только один pool.Release(insance1); ThrowsAssert.Throws <TimeoutException>(() => pool.TryFlush()); var pool2 = new ThirdPartyPool(0, 2); pool.FlushTimeOut = 1; var insance = pool.TakeInstance(); pool.Release(insance1); Action <ThirdParty> longTimeDestroy = obj => { Thread.Sleep(35000); }; // слишком длительная очистка объекта ThrowsAssert.Throws <TimeoutException>(() => pool.TryFlush(longTimeDestroy)); }
public void PoolFlushing() { var pool = new ThirdPartyPool(0, 3); var insanceArray = new List <PoolInstance <ThirdParty> >(); insanceArray.Add(pool.TakeInstance()); insanceArray.Add(pool.TakeInstance()); insanceArray.Add(pool.TakeInstance()); Assert.AreEqual(3, pool.TotalCount); insanceArray.ForEach(insance => pool.Release(insance)); pool.TryFlush(); insanceArray.Clear(); Assert.IsTrue(insanceArray.All(inst => inst.Object.Disposed)); Assert.AreEqual(0, pool.TotalCount); // recycle pool and manual flush insanceArray.Add(pool.TakeInstance()); insanceArray.Add(pool.TakeInstance()); Assert.AreEqual(2, pool.TotalCount); insanceArray.ForEach(insance => pool.Release(insance)); Action <ThirdParty> destroyer = obj => { obj.ManualDisposed = true; }; pool.TryFlush(destroyer); Assert.IsTrue(insanceArray.All(inst => inst.Object.ManualDisposed)); Assert.AreEqual(0, pool.TotalCount); }