Skip to content

Commit 5e5a3f6

Browse files
committed
More tests
1 parent 701c04e commit 5e5a3f6

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3ConnectionTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,26 @@ await WaitForConnectionErrorAsync<Http3ConnectionErrorException>(
110110
expectedErrorCode: Http3ErrorCode.StreamCreationError,
111111
expectedErrorMessage: CoreStrings.FormatHttp3ControlStreamErrorMultipleInboundStreams(name));
112112
}
113+
114+
[Theory]
115+
[InlineData(nameof(Http3FrameType.Data))]
116+
[InlineData(nameof(Http3FrameType.Headers))]
117+
[InlineData(nameof(Http3FrameType.PushPromise))]
118+
public async Task ControlStream_UnexpectedFrameType_ConnectionError(string frameType)
119+
{
120+
await InitializeConnectionAsync(_noopApplication);
121+
122+
var controlStream = await CreateControlStream();
123+
124+
var frame = new Http3RawFrame();
125+
frame.Type = Enum.Parse<Http3FrameType>(frameType);
126+
await controlStream.SendFrameAsync(frame, Memory<byte>.Empty);
127+
128+
await WaitForConnectionErrorAsync<Http3ConnectionErrorException>(
129+
ignoreNonGoAwayFrames: true,
130+
expectedLastStreamId: 0,
131+
expectedErrorCode: Http3ErrorCode.UnexpectedFrame,
132+
expectedErrorMessage: CoreStrings.FormatHttp3ErrorUnsupportedFrameOnControlStream(Http3Formatting.ToFormattedType(frame.Type)));
133+
}
113134
}
114135
}

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,20 @@ internal async ValueTask<Http3ControlStream> GetInboundControlStream()
121121
{
122122
if (_inboundControlStream == null)
123123
{
124-
return await CreateNewInboundControlStream();
125-
}
126-
127-
return null;
128-
}
129-
130-
internal async ValueTask<Http3ControlStream> CreateNewInboundControlStream()
131-
{
132-
var reader = MultiplexedConnectionContext.ToClientAcceptQueue.Reader;
133-
while (await reader.WaitToReadAsync())
134-
{
135-
while (reader.TryRead(out var stream))
124+
var reader = MultiplexedConnectionContext.ToClientAcceptQueue.Reader;
125+
while (await reader.WaitToReadAsync())
136126
{
137-
_inboundControlStream = stream;
138-
var streamId = await stream.TryReadStreamIdAsync();
139-
Debug.Assert(streamId == 0, "StreamId sent that was non-zero, which isn't handled by tests");
140-
return _inboundControlStream;
127+
while (reader.TryRead(out var stream))
128+
{
129+
_inboundControlStream = stream;
130+
var streamId = await stream.TryReadStreamIdAsync();
131+
Debug.Assert(streamId == 0, "StreamId sent that was non-zero, which isn't handled by tests");
132+
return _inboundControlStream;
133+
}
141134
}
142135
}
143136

144-
throw new InvalidOperationException("Should never reach here.");
137+
return null;
145138
}
146139

147140
internal async Task WaitForConnectionErrorAsync<TException>(bool ignoreNonGoAwayFrames, long expectedLastStreamId, Http3ErrorCode expectedErrorCode, params string[] expectedErrorMessage)
@@ -464,21 +457,12 @@ internal async Task WaitForStreamErrorAsync(Http3ErrorCode protocolError, string
464457
_testBase.Logger.LogTrace("Input is completed");
465458

466459
Assert.True(readResult.IsCompleted);
467-
//try
468-
{
469-
Assert.Equal(protocolError, (Http3ErrorCode)Error);
460+
Assert.Equal(protocolError, (Http3ErrorCode)Error);
470461

471-
if (expectedErrorMessage != null)
472-
{
473-
Assert.Contains(_testBase.LogMessages, m => m.Exception?.Message.Contains(expectedErrorMessage) ?? false);
474-
}
462+
if (expectedErrorMessage != null)
463+
{
464+
Assert.Contains(_testBase.LogMessages, m => m.Exception?.Message.Contains(expectedErrorMessage) ?? false);
475465
}
476-
//catch (Exception ex)
477-
//{
478-
// Debugger.Launch();
479-
// string s = ex.Message;
480-
// throw;
481-
//}
482466
}
483467
}
484468

0 commit comments

Comments
 (0)