public void DoesNotGoBelowMinimumThreads( ) { ThreadManager tm = new ThreadManager(1, 100, TimeSpan.MaxValue, TimeSpan.MaxValue, 100, TimeSpan.FromMilliseconds(100)); System.Threading.Thread.Sleep(200); Assert.AreEqual(1, tm.NumThreads, "Spawned more than the minimum threads?"); bool result = tm.DespawnThreadIfNeeded(); Assert.IsFalse(result, "Reported that it despawned a thread when at minimum."); Assert.AreEqual(1, tm.NumThreads, "Despawned a thread to get below minimum."); tm = new ThreadManager(5, 100, TimeSpan.MaxValue, TimeSpan.MaxValue, 100, TimeSpan.FromMilliseconds(100)); System.Threading.Thread.Sleep(200); Assert.AreEqual(5, tm.NumThreads, "Spawned more than the minimum threads?"); result = tm.DespawnThreadIfNeeded(); Assert.IsFalse(result, "Reported that it despawned a thread when at minimum."); Assert.AreEqual(5, tm.NumThreads, "Despawned a thread to get below minimum."); }
public void DestroysThreadsWhenOldEnough( ) { tm.SpawnThread(); System.Threading.Thread.Sleep(300); int cur_threads = tm.NumThreads; bool result = tm.DespawnThreadIfNeeded(); Assert.IsTrue(result, "Did not report that it despawned a thread."); Assert.IsTrue(cur_threads > tm.NumThreads, "Did not actually despawn a thread."); ThreadManager tm2 = new ThreadManager(TimeSpan.MinValue, TimeSpan.MaxValue, 100, TimeSpan.FromMilliseconds(1)); tm2.SpawnThread(); cur_threads = tm2.NumThreads; System.Threading.Thread.Sleep(10); result = tm2.DespawnThreadIfNeeded(); Assert.IsTrue(result, "Did not report that it despawned a thread."); Assert.IsTrue(cur_threads > tm2.NumThreads, "Did not actually despawn a thread."); }