public override async Task <HttpTestConnection> AcceptAsync() { Connection?connection = await _listener.AcceptConnectionAsync().ConfigureAwait(false); Debug.Assert(connection != null); return(new Http1TestConnection(connection)); }
public async Task Connect_Success(bool clientFirst) { await using ConnectionFactory factory = new MemoryConnectionFactory(); await using ConnectionListener listener = await factory.ListenAsync(); using var semaphore = new SemaphoreSlim(0); await RunClientServer(async () => { if (!clientFirst) { bool success = await semaphore.WaitAsync(10_000); Assert.True(success); } ValueTask<Connection> task = factory.ConnectAsync(listener.EndPoint!); if (clientFirst) semaphore.Release(); await using Connection connection = await task; }, async () => { if (clientFirst) { bool success = await semaphore.WaitAsync(10_000); Assert.True(success); } ValueTask<Connection?> task = listener.AcceptConnectionAsync(); if (!clientFirst) semaphore.Release(); await using Connection? connection = await task; Assert.NotNull(connection); }); }
public async Task Listener_DisposeCancelsAccept_Success() { await using ConnectionFactory factory = new MemoryConnectionFactory(); await using ConnectionListener listener = await factory.ListenAsync(); ValueTask<Connection?> acceptTask = listener.AcceptConnectionAsync(); await listener.DisposeAsync(); Connection? connection = await acceptTask; Assert.Null(connection); }
public async Task Connect_SelfSigned_Success() { var protocols = new List <SslApplicationProtocol> { new SslApplicationProtocol("test") }; var connectProperties = new ConnectionProperties(); connectProperties.Add(SslConnectionFactory.SslClientAuthenticationOptionsPropertyKey, new SslClientAuthenticationOptions { TargetHost = "localhost", ApplicationProtocols = protocols, RemoteCertificateValidationCallback = delegate { return(true); } }); var listenProperties = new ConnectionProperties(); listenProperties.Add(SslConnectionFactory.SslServerAuthenticationOptionsPropertyKey, new SslServerAuthenticationOptions { ApplicationProtocols = protocols, ServerCertificate = TestCertificates.GetSelfSigned13ServerCertificate() }); byte[] sendBuffer = Encoding.ASCII.GetBytes("Testing 123"); await using ConnectionFactory factory = new SslConnectionFactory(new MemoryConnectionFactory()); await using ConnectionListener listener = await factory.ListenAsync(options : listenProperties); await RunClientServer( async() => { await using Connection connection = await factory.ConnectAsync(listener.EndPoint !, connectProperties); await connection.Stream.WriteAsync(sendBuffer); }, async() => { await using Connection? connection = await listener.AcceptConnectionAsync(); Assert.NotNull(connection); Debug.Assert(connection != null); byte[] buffer = new byte[sendBuffer.Length + 1]; int readLen = await connection.Stream.ReadAsync(buffer); Assert.Equal(sendBuffer, buffer[..readLen]);