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

Fix compilation of unit tests. #9

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public static async ValueTask<ManagedQuicConnection> ConnectAsync(QuicClientConn
/// If true, the connection is in closing or draining state and will be considered close at
/// <see cref="_closingPeriodEndTimestamp"/> at the latest.
/// </summary>
private bool IsClosing => _closingPeriodEndTimestamp != null;
internal bool IsClosing => _closingPeriodEndTimestamp != null;

private bool Connected => HandshakeConfirmed;
internal bool Connected => HandshakeConfirmed;

/// <summary>
/// Timestamp when the connection close will be initiated due to lack of packets from peer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void ConnectionCloseWhenAckingFuturePacket()

Send1Rtt(Server, Client)
.ShouldHaveConnectionClose(TransportErrorCode.ProtocolViolation,
QuicError.InvalidAckRange,
QuicTransportError.InvalidAckRange,
FrameType.Ack);
}

Expand All @@ -54,7 +54,7 @@ public void ConnectionCloseWhenAckingNegativePacket()

Send1Rtt(Server, Client)
.ShouldHaveConnectionClose(TransportErrorCode.ProtocolViolation,
QuicError.InvalidAckRange,
QuicTransportError.InvalidAckRange,
FrameType.Ack);
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task TestAckNonContiguousRanges()

// we enforce sending packets by writing one byte, coincidentally containing the value of expected packet
// number for better testing
var clientStream = await Client.OpenUnidirectionalStreamAsync();
var clientStream = await Client.OpenOutboundStreamAsync(QuicStreamType.Unidirectional);

for (int i = 0; i <= last; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void ClosesConnectionWhenChangingSequenceNumber()
// now we are in trouble
Send1Rtt(Client, Server).ShouldHaveConnectionClose(
TransportErrorCode.ProtocolViolation,
QuicError.InconsistentNewConnectionIdFrame,
QuicTransportError.InconsistentNewConnectionIdFrame,
FrameType.NewConnectionId);
}

Expand All @@ -73,7 +73,7 @@ public void ClosesConnectionWhenChangingStatelessResetToken()
// now we are in trouble
Send1Rtt(Client, Server).ShouldHaveConnectionClose(
TransportErrorCode.ProtocolViolation,
QuicError.InconsistentNewConnectionIdFrame,
QuicTransportError.InconsistentNewConnectionIdFrame,
FrameType.NewConnectionId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public async Task CausesReadStreamOperationsToThrow()
packet.Frames.Add(new ResetStreamFrame()
{
FinalSize = 0,
StreamId = stream.StreamId,
StreamId = stream.Id,
ApplicationErrorCode = errorCode
});
});

var exception = Assert.Throws<QuicStreamAbortedException>(() => stream.Read(Span<byte>.Empty));
Assert.Equal(errorCode, exception.ErrorCode);
var exception = AssertThrowsQuicException(QuicError.StreamAborted, () => stream.Read(Span<byte>.Empty));
Assert.Equal(errorCode, exception.ApplicationErrorCode);
}

private void CloseConnectionCommon(ResetStreamFrame frame, TransportErrorCode errorCode, string reason)
Expand All @@ -59,18 +59,19 @@ public void ClosesConnection_WhenReceivedForNonReadableStream()
StreamId = StreamHelpers.ComposeStreamId(StreamType.ClientInitiatedUnidirectional, 0),
ApplicationErrorCode = 14
},
TransportErrorCode.StreamStateError, QuicError.StreamNotReadable);
TransportErrorCode.StreamStateError, QuicTransportError.StreamNotReadable);
}

[Fact]
public void ClosesConnection_WhenViolatingStreamLimit()
{
CloseConnectionCommon(new ResetStreamFrame()
{
StreamId = StreamHelpers.ComposeStreamId(StreamType.ServerInitiatedUnidirectional, ListenerOptions.MaxBidirectionalStreams + 1),
// TODO: value of streamId based on listener options
StreamId = StreamHelpers.ComposeStreamId(StreamType.ServerInitiatedUnidirectional, int.MaxValue),
ApplicationErrorCode = 14
},
TransportErrorCode.StreamLimitError, QuicError.StreamsLimitViolated);
TransportErrorCode.StreamLimitError, QuicTransportError.StreamsLimitViolated);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task ElicitsResetStream()

var frame = Send1RttWithFrame<ResetStreamFrame>(Server, Client);

Assert.Equal(stream.StreamId, frame.StreamId);
Assert.Equal(stream.Id, frame.StreamId);
Assert.Equal(errorCode, frame.ApplicationErrorCode);
Assert.Equal(0, frame.FinalSize);
}
Expand All @@ -54,10 +54,10 @@ public async Task ClosesConnection_WhenReceivedForNonWritableStream()

CloseConnectionCommon(new StopSendingFrame()
{
StreamId = stream.StreamId,
StreamId = stream.Id,
ApplicationErrorCode = 14
},
TransportErrorCode.StreamStateError, QuicError.StreamNotWritable);
TransportErrorCode.StreamStateError, QuicTransportError.StreamNotWritable);
}

[Fact]
Expand All @@ -69,7 +69,7 @@ public void ClosesConnection_WhenReceivedForUncreatedLocallyInitiatedStream()
StreamId = StreamHelpers.ComposeStreamId(StreamType.ServerInitiatedBidirectional, 0),
ApplicationErrorCode = 14
},
TransportErrorCode.StreamStateError, QuicError.StreamNotCreated);
TransportErrorCode.StreamStateError, QuicTransportError.StreamNotCreated);
}

[Fact]
Expand All @@ -78,10 +78,11 @@ public void ClosesConnection_WhenViolatingStreamLimit()
CloseConnectionCommon(
new StopSendingFrame()
{
StreamId = StreamHelpers.ComposeStreamId(StreamType.ClientInitiatedBidirectional, ListenerOptions.MaxBidirectionalStreams + 1),
// TODO: value of streamId based on listener options
StreamId = StreamHelpers.ComposeStreamId(StreamType.ClientInitiatedBidirectional, int.MaxValue),
ApplicationErrorCode = 14
},
TransportErrorCode.StreamLimitError, QuicError.StreamsLimitViolated);
TransportErrorCode.StreamLimitError, QuicTransportError.StreamsLimitViolated);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void SendsConnectionCloseOnSmallClientInitial()

initial.ShouldHaveConnectionClose(
TransportErrorCode.ProtocolViolation,
QuicError.InitialPacketTooShort);
QuicTransportError.InitialPacketTooShort);
});
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public void SendsConnectionCloseWhenServerSendsToken()
var packet = (CommonPacket)SendFlight(Client, Server).Packets[0];
packet.ShouldHaveConnectionClose(
TransportErrorCode.ProtocolViolation,
QuicError.UnexpectedToken);
QuicTransportError.UnexpectedToken);
}

[Fact]
Expand All @@ -198,7 +198,7 @@ public void SendsConnectionCloseWhenReservedBitsAreSet_LongHeader()
InterceptInitial(Server, Client, initial =>
{
initial.ShouldHaveConnectionClose(TransportErrorCode.ProtocolViolation,
QuicError.InvalidReservedBits);
QuicTransportError.InvalidReservedBits);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Net.Quic.Tests.Harness;
using System.Net.Security;
using System.Threading.Channels;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -52,6 +53,7 @@ public class ManualTransmissionQuicTestBase
private static readonly IPEndPoint _dummyListenEndpoint = new IPEndPoint(IPAddress.Any, 0);

internal readonly QuicClientConnectionOptions ClientOptions;
internal readonly QuicServerConnectionOptions ServerOptions;
internal readonly QuicListenerOptions ListenerOptions;

internal readonly ManagedQuicConnection Client;
Expand All @@ -75,21 +77,26 @@ public class ManualTransmissionQuicTestBase

protected ManualTransmissionQuicTestBase(ITestOutputHelper output)
{
ListenerOptions = new QuicListenerOptions
ServerOptions = new QuicServerConnectionOptions
{
// TODO:
//CertificateFilePath = CertificateFilePath,
//PrivateKeyFilePath = PrivateKeyFilePath,
ServerAuthenticationOptions = new SslServerAuthenticationOptions()
{
ApplicationProtocols = new List<SslApplicationProtocol>()
{
new SslApplicationProtocol("quictest")
}
},
};
ListenerOptions = new QuicListenerOptions
{
ApplicationProtocols = new List<SslApplicationProtocol>()
{
new SslApplicationProtocol("quictest")
},
ConnectionOptionsCallback = delegate { return ValueTask.FromResult(ServerOptions); },
ListenEndPoint = new IPEndPoint(IPAddress.Loopback, 0)
};
Server = CreateServer(ListenerOptions);
Server = CreateServer(ServerOptions, ListenerOptions);

ClientOptions = new QuicClientConnectionOptions()
{
Expand Down Expand Up @@ -124,10 +131,10 @@ private static ManagedQuicConnection CreateClient(QuicClientConnectionOptions op
return new ManagedQuicConnection(options, MockTlsFactory.Instance);
}

private static ManagedQuicConnection CreateServer(QuicListenerOptions options)
private static ManagedQuicConnection CreateServer(QuicServerConnectionOptions options, QuicListenerOptions listenerOptions)
{
var ctx = new QuicServerSocketContext(new IPEndPoint(IPAddress.Any, 0),
options, Channel.CreateUnbounded<ManagedQuicConnection>().Writer, MockTlsFactory.Instance);
listenerOptions, Channel.CreateUnbounded<ManagedQuicConnection>().Writer, MockTlsFactory.Instance);
Span<byte> odcid = stackalloc byte[20];
return new ManagedQuicConnection(options, new QuicConnectionContext(ctx, _dummyListenEndpoint, odcid, MockTlsFactory.Instance), _dummyListenEndpoint, odcid, MockTlsFactory.Instance);
}
Expand Down Expand Up @@ -465,5 +472,11 @@ internal void LogFlightPackets(PacketBase packet, ManagedQuicConnection sender,
{
LogFlightPackets(new []{packet}, sender, lost);
}

internal QuicException AssertThrowsQuicException(QuicError expectedError, Action action) =>
AssertHelpers.ThrowsQuicException(expectedError, action);

internal Task<QuicException> AssertThrowsQuicExceptionAsync(QuicError expectedError, Func<Task> action) =>
AssertHelpers.ThrowsQuicExceptionAsync(expectedError, action);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ public async Task RequestingAbortAbortsReaders()
{
var destination = new byte[100];

var exnTask = Assert.ThrowsAsync<QuicStreamAbortedException>(
var exnTask = AssertHelpers.ThrowsQuicExceptionAsync(QuicError.StreamAborted,
() => stream.DeliverAsync(destination, CancellationToken.None).AsTask());

stream.RequestAbort(10000);
stream.OnResetStream(10000);

var exn = await exnTask.WaitAsync(TimeSpan.FromMilliseconds(5_000));
Assert.Equal(10000, exn.ErrorCode);
Assert.Equal(10000, exn.ApplicationErrorCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task RequestingAbortAbortsWriters()
{
var destination = new byte[100];

var exnTask = Assert.ThrowsAsync<QuicStreamAbortedException>(
var exnTask = AssertHelpers.ThrowsQuicExceptionAsync(QuicError.StreamAborted,
async () =>
{
while (true)
Expand All @@ -154,10 +154,10 @@ public async Task RequestingAbortAbortsWriters()
}
});

stream.RequestAbort(10000);
stream.RequestAbort(10000, false);

var exn = await exnTask.WaitAsync(TimeSpan.FromMilliseconds(5_000));
Assert.Equal(10000, exn.ErrorCode);
Assert.Equal(10000, exn.ApplicationErrorCode);
}
}
}
Loading