public void It_throws_exception_if_adding_is_not_completed() { using (var threadPool = new ConsumerThreadPool <int>(2, item => { Thread.Sleep(1000); return(true); })) { for (var i = 0; i < 10; i++) { threadPool.Add(i); } // ReSharper disable once AccessToDisposedClosure Assert.ThrowsAsync <InvalidOperationException>(() => threadPool.WaitForCompletion()); } }
public async Task It_reports_successful_when_processItem_returns_true() { using (var threadPool = new ConsumerThreadPool <int>(2, item => true)) { for (var i = 0; i < 100; i++) { threadPool.Add(i); } threadPool.CompleteAdding(); await threadPool.WaitForCompletion(); Assert.That(threadPool.ItemsSuccessful, Is.EqualTo(threadPool.TotalItems)); } }
public async Task It_reports_progress() { using (var threadPool = new ConsumerThreadPool <int>(2, item => false)) { for (var i = 0; i < 100; i++) { threadPool.Add(i); } threadPool.CompleteAdding(); await threadPool.WaitForCompletion(); Assert.That(threadPool.Progress, Is.EqualTo(100)); } }
public void It_does_not_throw_exception_if_ignoreIsAddingCompleted_is_true() { var cancellationTokenSource = new CancellationTokenSource(); using (var threadPool = new ConsumerThreadPool <int>(2, item => true, cancellationTokenSource.Token)) { for (var i = 0; i < 100; i++) { threadPool.Add(i); } Task.Run(async() => { await Task.Delay(100); cancellationTokenSource.Cancel(); }); // ReSharper disable once AccessToDisposedClosure Assert.DoesNotThrowAsync(() => threadPool.WaitForCompletion(true)); } }