private void RefreshSchedulerInstance() { sch = null; GC.Collect(); sch = new TPLTaskScheduler <string>(); }
public void AllTasksCompleted_With_An_Empty_Queue_It_Should_Return_TrulyValue() { //ARRANGE var schTemp = new TPLTaskScheduler <string>(consumersCount: 1); var items = new WorkItem <string>[] { new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) , new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) , new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) , new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) }; schTemp.EnqueueWork(items); //ACT,ASSERT schTemp.AllTasksCompleted.Should().BeFalse(); schTemp.Dispose(); schTemp = null; }
public void TPLTaskScheduler_With_Logger_It_Should_LogDebug_Starting_ConsumerTasks() { //ARRANGE var consCount = 5; var loggerMock = new Mock <ILogger>(); //ACT var scheduler = new TPLTaskScheduler(loggerMock.Object, consumersCount: consCount); loggerMock.Setup(i => i.Debug( It.Is <string>(m => m.Contains("starting", StringComparison.InvariantCultureIgnoreCase) && Regex.IsMatch(m, @"\d+")))); //ASSERT loggerMock.Verify(i => i.Debug( It.Is <string>(m => m.Contains("starting", StringComparison.InvariantCultureIgnoreCase) && Regex.IsMatch(m, @"\d+"))) , Times.Exactly(consCount)); }
public void EnqueueWork_OnMaxItemQueue_Reached_It_Should_Throw_InvalidOperationException() { //ARRANGE var schTemp = new TPLTaskScheduler <string>(consumersCount: 1, maxQueueItems: 1); var items = new WorkItem <string>[] { new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) , new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) , new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) , new WorkItem <string>(() => { Thread.Sleep(2 * 1000); return(string.Empty); }) }; Action action = () => schTemp.EnqueueWork(items); //ACT,ASSERT action.Should().Throw <InvalidOperationException>(); schTemp.Dispose(); schTemp = null; }