|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved.
|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Collections.Generic;
|
| 6 | +using System.IO.Pipelines; |
5 | 7 | using System.Linq;
|
6 | 8 | using System.Threading.Tasks;
|
7 | 9 | using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
|
@@ -42,5 +44,27 @@ public void OnConnectionCreatesLogScopeWithConnectionId()
|
42 | 44 | // Verify the scope was disposed after request processing completed
|
43 | 45 | Assert.True(((TestKestrelTrace)serviceContext.Log).Logger.Scopes.IsEmpty);
|
44 | 46 | }
|
| 47 | + |
| 48 | + [Fact] |
| 49 | + public async Task OnConnectionCompletesTransportPipesAfterReturning() |
| 50 | + { |
| 51 | + var serviceContext = new TestServiceContext(); |
| 52 | + var tcs = new TaskCompletionSource<object>(); |
| 53 | + var dispatcher = new ConnectionDispatcher(serviceContext, _ => Task.CompletedTask); |
| 54 | + |
| 55 | + var mockConnection = new Mock<TransportConnection>(); |
| 56 | + var mockPipeReader = new Mock<PipeReader>(); |
| 57 | + var mockPipeWriter = new Mock<PipeWriter>(); |
| 58 | + var mockPipe = new Mock<IDuplexPipe>(); |
| 59 | + mockPipe.Setup(m => m.Input).Returns(mockPipeReader.Object); |
| 60 | + mockPipe.Setup(m => m.Output).Returns(mockPipeWriter.Object); |
| 61 | + mockConnection.Setup(m => m.Transport).Returns(mockPipe.Object); |
| 62 | + var connection = mockConnection.Object; |
| 63 | + |
| 64 | + await dispatcher.OnConnection(connection); |
| 65 | + |
| 66 | + mockPipeWriter.Verify(m => m.Complete(It.IsAny<Exception>()), Times.Once()); |
| 67 | + mockPipeReader.Verify(m => m.Complete(It.IsAny<Exception>()), Times.Once()); |
| 68 | + } |
45 | 69 | }
|
46 | 70 | }
|
0 commit comments