|
8 | 8 | using System.Net.Security;
|
9 | 9 | using System.Net.Sockets;
|
10 | 10 | using System.Security.Authentication;
|
| 11 | +using System.Security.Cryptography; |
11 | 12 | using System.Security.Cryptography.X509Certificates;
|
12 | 13 | using System.Text;
|
13 | 14 | using System.Threading;
|
@@ -801,5 +802,59 @@ await Task.Run(async () =>
|
801 | 802 | await Assert.ThrowsAsync<QuicOperationAbortedException>(() => serverStream.ReadAsync(buffer).AsTask());
|
802 | 803 | }).WaitAsync(TimeSpan.FromMilliseconds(PassingTestTimeoutMilliseconds));
|
803 | 804 | }
|
| 805 | + |
| 806 | + [Theory] |
| 807 | + [InlineData(true)] |
| 808 | + [InlineData(false)] |
| 809 | + public async Task BigWrite_SmallRead_Success(bool closeWithData) |
| 810 | + { |
| 811 | + const int size = 100; |
| 812 | + (QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(); |
| 813 | + using (clientConnection) |
| 814 | + using (serverConnection) |
| 815 | + { |
| 816 | + byte[] buffer = new byte[1] { 42 }; |
| 817 | + |
| 818 | + QuicStream clientStream = clientConnection.OpenBidirectionalStream(); |
| 819 | + Task<QuicStream> t = serverConnection.AcceptStreamAsync().AsTask(); |
| 820 | + await TaskTimeoutExtensions.WhenAllOrAnyFailed(clientStream.WriteAsync(buffer).AsTask(), t, PassingTestTimeoutMilliseconds); |
| 821 | + QuicStream serverStream = t.Result; |
| 822 | + Assert.Equal(1, await serverStream.ReadAsync(buffer)); |
| 823 | + |
| 824 | + // streams are new established and in good shape. |
| 825 | + using (clientStream) |
| 826 | + using (serverStream) |
| 827 | + { |
| 828 | + byte[] expected = RandomNumberGenerator.GetBytes(size); |
| 829 | + byte[] actual = new byte[size]; |
| 830 | + |
| 831 | + // should be small enough to fit. |
| 832 | + await serverStream.WriteAsync(expected, closeWithData); |
| 833 | + |
| 834 | + // Add delay to have chance to receive the 100b block before ReadAsync starts. |
| 835 | + await Task.Delay(10); |
| 836 | + int remaining = size; |
| 837 | + int readLength; |
| 838 | + while (remaining > 0) |
| 839 | + { |
| 840 | + readLength = await clientStream.ReadAsync(new Memory<byte>(actual, size - remaining, 1)); |
| 841 | + Assert.Equal(1, readLength); |
| 842 | + remaining--; |
| 843 | + } |
| 844 | + |
| 845 | + Assert.Equal(expected, actual); |
| 846 | + |
| 847 | + if (!closeWithData) |
| 848 | + { |
| 849 | + serverStream.Shutdown(); |
| 850 | + } |
| 851 | + |
| 852 | + readLength = await clientStream.ReadAsync(actual); |
| 853 | + Assert.Equal(0, readLength); |
| 854 | + |
| 855 | + Assert.Equal(expected, actual); |
| 856 | + } |
| 857 | + } |
| 858 | + } |
804 | 859 | }
|
805 | 860 | }
|
0 commit comments