public async Task QueueOnExitCalledEvenIfNextErrors() { var flag = false; var testQueue = new TestQueue( onTryEnter: (_) => true, onExit: () => { flag = true; }); var middleware = TestUtils.CreateTestMiddleware( queue: testQueue, next: httpContext => { throw new DivideByZeroException(); }); Assert.Equal(0, testQueue.QueuedRequests); await Assert.ThrowsAsync <DivideByZeroException>(() => middleware.Invoke(new DefaultHttpContext())).OrTimeout(); Assert.Equal(0, testQueue.QueuedRequests); Assert.True(flag); }
public void EventCountersTrackQueuedRequests() { var blocker = new TaskCompletionSource <bool>(); var testQueue = new TestQueue( onTryEnter: async(_) => { return(await blocker.Task); }); var middleware = TestUtils.CreateTestMiddleware(testQueue); Assert.Equal(0, testQueue.QueuedRequests); var task1 = middleware.Invoke(new DefaultHttpContext()); Assert.False(task1.IsCompleted); Assert.Equal(1, testQueue.QueuedRequests); blocker.SetResult(true); Assert.Equal(0, testQueue.QueuedRequests); }