Skip to content

Commit b0d7fc9

Browse files
committed
Test cleanup
1 parent 58205e6 commit b0d7fc9

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/Servers/HttpSys/test/FunctionalTests/Http2Tests.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace Microsoft.AspNetCore.Server.HttpSys.FunctionalTests
1616
{
1717
public class Http2Tests
1818
{
19-
[ConditionalFact]
20-
// TODO: Max OS Version attribute
19+
[ConditionalFact(Skip = "https://github.com/aspnet/AspNetCore/issues/17420")]
20+
// TODO: Max OS Version attribute 19H1
2121
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10, SkipReason = "Http2 requires Win10")]
2222
public async Task ConnectionClose_NoOSSupport_NoGoAway()
2323
{
@@ -86,7 +86,7 @@ public async Task ConnectionClose_NoOSSupport_NoGoAway()
8686
}
8787

8888
[ConditionalFact]
89-
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10_19H2, SkipReason = "Http2 requires Win10")]
89+
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10_19H2, SkipReason = "GoAway support was added in Win10_19H2.")]
9090
public async Task ConnectionClose_OSSupport_SendsGoAway()
9191
{
9292
using var server = Utilities.CreateDynamicHttpsServer(out var address, httpContext =>
@@ -115,8 +115,7 @@ public async Task ConnectionClose_OSSupport_SendsGoAway()
115115
var headersFrame = await http2Utilities.ReceiveFrameAsync();
116116

117117
Assert.Equal(Http2FrameType.HEADERS, headersFrame.Type);
118-
Assert.True((headersFrame.Flags & (byte)Http2HeadersFrameFlags.END_HEADERS) != 0);
119-
Assert.True((headersFrame.Flags & (byte)Http2HeadersFrameFlags.END_STREAM) != 0);
118+
Assert.Equal(Http2HeadersFrameFlags.END_HEADERS, headersFrame.HeadersFlags);
120119

121120
logger.LogInformation("Received headers in a single frame.");
122121

@@ -126,7 +125,26 @@ public async Task ConnectionClose_OSSupport_SendsGoAway()
126125
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
127126
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
128127

129-
await http2Utilities.StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
128+
var dataFrame = await http2Utilities.ReceiveFrameAsync();
129+
Assert.Equal(Http2FrameType.DATA, dataFrame.Type);
130+
Assert.Equal(Http2DataFrameFlags.END_STREAM, dataFrame.DataFlags);
131+
Assert.Equal(0, dataFrame.PayloadLength);
132+
133+
// TODO: Why doesn't HttpSys send a final GoAway or close the connection?
134+
// https://tools.ietf.org/html/rfc7540#section-6.8
135+
// A server that is attempting to gracefully shut down a
136+
// connection SHOULD send an initial GOAWAY frame with the last stream
137+
// identifier set to 2^31-1 and a NO_ERROR code. This signals to the
138+
// client that a shutdown is imminent and that initiating further
139+
// requests is prohibited. After allowing time for any in-flight stream
140+
// creation (at least one round-trip time), the server can send another
141+
// GOAWAY frame with an updated last stream identifier. This ensures
142+
// that a connection can be cleanly shut down without losing requests.
143+
//
144+
// await http2Utilities.StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
145+
// or
146+
// await http2Utilities.SendGoAwayAsync();
147+
// await http2Utilities.WaitForConnectionStopAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
130148

131149
logger.LogInformation("Connection stopped.");
132150
};

src/Shared/Http2cat/Http2CatHostedService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public async Task RunAsync()
5353
_logger.LogInformation($"Connected to '{endpoint}'.");
5454

5555
var originalTransport = context.Transport;
56+
IAsyncDisposable sslState = null;
5657
if (address.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
5758
{
5859
_logger.LogInformation("Starting TLS handshake.");
@@ -63,6 +64,7 @@ public async Task RunAsync()
6364

6465
var sslDuplexPipe = new SslDuplexPipe(context.Transport, inputPipeOptions, outputPipeOptions);
6566
var sslStream = sslDuplexPipe.Stream;
67+
sslState = sslDuplexPipe;
6668

6769
context.Transport = sslDuplexPipe;
6870

@@ -92,6 +94,11 @@ await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
9294
{
9395
// Unwind Https for shutdown. This must happen before context goes ot of scope or else DisposeAsync will hang
9496
context.Transport = originalTransport;
97+
98+
if (sslState != null)
99+
{
100+
await sslState.DisposeAsync();
101+
}
95102
}
96103
}
97104
}

0 commit comments

Comments
 (0)