public void Enqueue_BatchesNotificationsByKey_ProcessesLast() { // Arrange var originalWorkItem = new ThrowingBatchableWorkItem(); var newestWorkItem = new TestBatchableWorkItem(); TestAccessor.BlockBackgroundWorkStart = new ManualResetEventSlim(initialState: false); // Act WorkQueue.Enqueue("key", originalWorkItem); WorkQueue.Enqueue("key", newestWorkItem); // Assert Assert.True(TestAccessor.IsScheduledOrRunning, "Queue should be scheduled during Enqueue"); Assert.NotEmpty(TestAccessor.Work); // Allow the background work to start. TestAccessor.BlockBackgroundWorkStart.Set(); TestAccessor.NotifyBackgroundWorkCompleted.Wait(TimeSpan.FromSeconds(3)); Assert.Empty(TestAccessor.Work); Assert.False(originalWorkItem.Processed); Assert.True(newestWorkItem.Processed); Assert.Empty(ErrorReporter.ReportedExceptions); }
public void Enqueue_ThrowingWorkItem_DoesNotPreventProcessingSubsequentItems() { // Arrange var throwingWorkItem = new ThrowingBatchableWorkItem(); var validWorkItem = new TestBatchableWorkItem(); TestAccessor.BlockBackgroundWorkStart = new ManualResetEventSlim(initialState: false); // Act WorkQueue.Enqueue("key", throwingWorkItem); WorkQueue.Enqueue("key2", validWorkItem); // Assert Assert.True(TestAccessor.IsScheduledOrRunning, "Queue should be scheduled during Enqueue"); Assert.NotEmpty(TestAccessor.Work); // Allow the background work to start. TestAccessor.BlockBackgroundWorkStart.Set(); TestAccessor.NotifyBackgroundWorkCompleted.Wait(TimeSpan.FromSeconds(3)); Assert.Empty(TestAccessor.Work); Assert.True(throwingWorkItem.Processed); Assert.True(validWorkItem.Processed); Assert.Single(ErrorReporter.ReportedExceptions); }