public void DoesNotDespawnWorkingThread( ) { ThreadManager tm = new ThreadManager(0, 1, TimeSpan.MinValue, TimeSpan.MaxValue, 1, TimeSpan.FromMilliseconds(10)); tm.SpawnThread(); ActionTask task = new ActionTask(( _ ) => System.Threading.Thread.Sleep(500), false); tm.EnqueueTask(task); tm.UnsafeUpdate(); System.Threading.Thread.Sleep(20); tm.UnsafeUpdate(); Assert.AreEqual(1, tm.NumThreads, "Despawned a thread while working."); }
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."); }