Skip to content

Commit

Permalink
fix few more QUIC tests that can hang (dotnet#59682)
Browse files Browse the repository at this point in the history
* fix few more tests that can hang

* update
  • Loading branch information
wfurt authored Sep 29, 2021
1 parent 5769db8 commit b3c592f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ public QuicConnectionTests(ITestOutputHelper output) : base(output) { }
public async Task TestConnect()
{
using QuicListener listener = CreateQuicListener();
IPEndPoint listenEndPoint = listener.ListenEndPoint;

using QuicConnection clientConnection = CreateQuicConnection(listenEndPoint);
using QuicConnection clientConnection = CreateQuicConnection(listener.ListenEndPoint);

Assert.False(clientConnection.Connected);
Assert.Equal(listenEndPoint, clientConnection.RemoteEndPoint);
Assert.Equal(listener.ListenEndPoint, clientConnection.RemoteEndPoint);

ValueTask connectTask = clientConnection.ConnectAsync();
QuicConnection serverConnection = await listener.AcceptConnectionAsync();
await connectTask;
ValueTask<QuicConnection> acceptTask = listener.AcceptConnectionAsync();

await new Task[] { connectTask.AsTask(), acceptTask.AsTask()}.WhenAllOrAnyFailed(PassingTestTimeoutMilliseconds);
QuicConnection serverConnection = acceptTask.Result;

Assert.True(clientConnection.Connected);
Assert.True(serverConnection.Connected);
Assert.Equal(listenEndPoint, serverConnection.LocalEndPoint);
Assert.Equal(listenEndPoint, clientConnection.RemoteEndPoint);
Assert.Equal(listener.ListenEndPoint, serverConnection.LocalEndPoint);
Assert.Equal(listener.ListenEndPoint, clientConnection.RemoteEndPoint);
Assert.Equal(clientConnection.LocalEndPoint, serverConnection.RemoteEndPoint);
Assert.Equal(ApplicationProtocol.ToString(), clientConnection.NegotiatedApplicationProtocol.ToString());
Assert.Equal(ApplicationProtocol.ToString(), serverConnection.NegotiatedApplicationProtocol.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,19 @@ static async Task MakeStreams(QuicConnection clientConnection, QuicConnection se
[Fact]
public async Task GetStreamIdWithoutStartWorks()
{
using QuicListener listener = CreateQuicListener();
using QuicConnection clientConnection = CreateQuicConnection(listener.ListenEndPoint);

ValueTask clientTask = clientConnection.ConnectAsync();
using QuicConnection serverConnection = await listener.AcceptConnectionAsync();
await clientTask;
(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection();

using QuicStream clientStream = clientConnection.OpenBidirectionalStream();
Assert.Equal(0, clientStream.StreamId);
using (clientConnection)
using (serverConnection)
{
using QuicStream clientStream = clientConnection.OpenBidirectionalStream();
Assert.Equal(0, clientStream.StreamId);

// TODO: stream that is opened by client but left unaccepted by server may cause AccessViolationException in its Finalizer
// explicitly closing the connections seems to help, but the problem should still be investigated, we should have a meaningful
// exception instead of AccessViolationException
await clientConnection.CloseAsync(0);
// TODO: stream that is opened by client but left unaccepted by server may cause AccessViolationException in its Finalizer
// explicitly closing the connections seems to help, but the problem should still be investigated, we should have a meaningful
// exception instead of AccessViolationException
await clientConnection.CloseAsync(0);
}
}

[Fact]
Expand Down Expand Up @@ -257,28 +256,22 @@ await RunClientServer(
public async Task TestStreams()
{
using QuicListener listener = CreateQuicListener();
IPEndPoint listenEndPoint = listener.ListenEndPoint;

using QuicConnection clientConnection = CreateQuicConnection(listenEndPoint);

Assert.False(clientConnection.Connected);
Assert.Equal(listenEndPoint, clientConnection.RemoteEndPoint);

ValueTask connectTask = clientConnection.ConnectAsync();
using QuicConnection serverConnection = await listener.AcceptConnectionAsync();
await connectTask;

Assert.True(clientConnection.Connected);
Assert.True(serverConnection.Connected);
Assert.Equal(listenEndPoint, serverConnection.LocalEndPoint);
Assert.Equal(listenEndPoint, clientConnection.RemoteEndPoint);
Assert.Equal(clientConnection.LocalEndPoint, serverConnection.RemoteEndPoint);

await CreateAndTestBidirectionalStream(clientConnection, serverConnection);
await CreateAndTestBidirectionalStream(serverConnection, clientConnection);
await CreateAndTestUnidirectionalStream(serverConnection, clientConnection);
await CreateAndTestUnidirectionalStream(clientConnection, serverConnection);
await clientConnection.CloseAsync(errorCode: 0);
(QuicConnection clientConnection, QuicConnection serverConnection) = await CreateConnectedQuicConnection(listener);
using (clientConnection)
using (serverConnection)
{
Assert.True(clientConnection.Connected);
Assert.True(serverConnection.Connected);
Assert.Equal(listener.ListenEndPoint, serverConnection.LocalEndPoint);
Assert.Equal(listener.ListenEndPoint, clientConnection.RemoteEndPoint);
Assert.Equal(clientConnection.LocalEndPoint, serverConnection.RemoteEndPoint);

await CreateAndTestBidirectionalStream(clientConnection, serverConnection);
await CreateAndTestBidirectionalStream(serverConnection, clientConnection);
await CreateAndTestUnidirectionalStream(serverConnection, clientConnection);
await CreateAndTestUnidirectionalStream(clientConnection, serverConnection);
await clientConnection.CloseAsync(errorCode: 0);
}
}

private static async Task CreateAndTestBidirectionalStream(QuicConnection c1, QuicConnection c2)
Expand Down

0 comments on commit b3c592f

Please sign in to comment.