Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for using SslStream for concurrent read/writes #36064

Merged
merged 1 commit into from Mar 15, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+49 −1
Diff settings

Always

Just for now

@@ -8,7 +8,6 @@
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using Xunit;
@@ -329,6 +328,55 @@ await serverSslStream.WriteAsync(new byte[] { 1 }, 0, 1)
}
}

[OuterLoop("Executes for several seconds")]
[Fact]
public async Task SslStream_ConcurrentBidirectionalReadsWrites_Success()
{
VirtualNetwork network = new VirtualNetwork();

using (var clientStream = new VirtualNetworkStream(network, isServer: false))
using (var serverStream = new NotifyReadVirtualNetworkStream(network, isServer: true))
using (var clientSslStream = new SslStream(clientStream, false, AllowAnyServerCertificate))
using (var serverSslStream = new SslStream(serverStream))
{
await DoHandshake(clientSslStream, serverSslStream);

const int BytesPerSend = 100;
DateTime endTime = DateTime.UtcNow + TimeSpan.FromSeconds(5);
await new Task[]
{
Task.Run(async delegate
{
var buffer = new byte[BytesPerSend];
while (DateTime.UtcNow < endTime)
{
await clientStream.WriteAsync(buffer, 0, buffer.Length);
int received = 0, bytesRead = 0;
while (received < BytesPerSend && (bytesRead = await serverStream.ReadAsync(buffer, 0, buffer.Length)) != 0)
{
received += bytesRead;
}
Assert.NotEqual(0, bytesRead);
}
}),
Task.Run(async delegate
{
var buffer = new byte[BytesPerSend];
while (DateTime.UtcNow < endTime)
{
await serverStream.WriteAsync(buffer, 0, buffer.Length);
int received = 0, bytesRead = 0;
while (received < BytesPerSend && (bytesRead = await clientStream.ReadAsync(buffer, 0, buffer.Length)) != 0)
{
received += bytesRead;
}
Assert.NotEqual(0, bytesRead);
}
})
}.WhenAllOrAnyFailed();
}
}

[Fact]
public async Task SslStream_StreamToStream_Dispose_Throws()
{
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.