Skip to content

Commit df5269f

Browse files
authored
React to regression in Http.Sys (#23590)
* React to regression in Http.Sys #23164 * Add granular version check
1 parent dae3b46 commit df5269f

File tree

1 file changed

+140
-3
lines changed

1 file changed

+140
-3
lines changed

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

+140-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,84 @@ namespace Microsoft.AspNetCore.Server.HttpSys.FunctionalTests
2020
{
2121
public class Http2Tests
2222
{
23+
// TODO: Remove when the regression is fixed.
24+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
25+
private static readonly Version Win10_Regressed_DataFrame = new Version(10, 0, 20145, 0);
26+
27+
[ConditionalFact]
28+
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10, SkipReason = "Http2 requires Win10")]
29+
public async Task EmptyResponse_200()
30+
{
31+
using var server = Utilities.CreateDynamicHttpsServer(out var address, httpContext =>
32+
{
33+
// Default 200
34+
return Task.CompletedTask;
35+
});
36+
37+
await new HostBuilder()
38+
.UseHttp2Cat(address, async h2Connection =>
39+
{
40+
await h2Connection.InitializeConnectionAsync();
41+
42+
h2Connection.Logger.LogInformation("Initialized http2 connection. Starting stream 1.");
43+
44+
await h2Connection.StartStreamAsync(1, Http2Utilities.BrowserRequestHeaders, endStream: true);
45+
46+
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
47+
{
48+
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
49+
});
50+
51+
var dataFrame = await h2Connection.ReceiveFrameAsync();
52+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
53+
{
54+
// TODO: Remove when the regression is fixed.
55+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
56+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 0);
57+
58+
dataFrame = await h2Connection.ReceiveFrameAsync();
59+
}
60+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);
61+
62+
h2Connection.Logger.LogInformation("Connection stopped.");
63+
})
64+
.Build().RunAsync();
65+
}
66+
67+
[ConditionalFact]
68+
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10, SkipReason = "Http2 requires Win10")]
69+
public async Task ResponseWithData_Success()
70+
{
71+
using var server = Utilities.CreateDynamicHttpsServer(out var address, httpContext =>
72+
{
73+
return httpContext.Response.WriteAsync("Hello World");
74+
});
75+
76+
await new HostBuilder()
77+
.UseHttp2Cat(address, async h2Connection =>
78+
{
79+
await h2Connection.InitializeConnectionAsync();
80+
81+
h2Connection.Logger.LogInformation("Initialized http2 connection. Starting stream 1.");
82+
83+
await h2Connection.StartStreamAsync(1, Http2Utilities.BrowserRequestHeaders, endStream: true);
84+
85+
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
86+
{
87+
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
88+
});
89+
90+
var dataFrame = await h2Connection.ReceiveFrameAsync();
91+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 11);
92+
93+
dataFrame = await h2Connection.ReceiveFrameAsync();
94+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);
95+
96+
h2Connection.Logger.LogInformation("Connection stopped.");
97+
})
98+
.Build().RunAsync();
99+
}
100+
23101
[ConditionalFact(Skip = "https://github.com/dotnet/aspnetcore/issues/17420")]
24102
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10, SkipReason = "Http2 requires Win10")]
25103
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10_19H1, SkipReason = "This is last version without GoAway support")]
@@ -95,6 +173,14 @@ await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
95173
});
96174

97175
var dataFrame = await h2Connection.ReceiveFrameAsync();
176+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
177+
{
178+
// TODO: Remove when the regression is fixed.
179+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
180+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 0);
181+
182+
dataFrame = await h2Connection.ReceiveFrameAsync();
183+
}
98184
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);
99185

100186
// Http.Sys doesn't send a final GoAway unless we ignore the first one and send 200 additional streams.
@@ -135,6 +221,14 @@ await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
135221
});
136222

137223
var dataFrame = await h2Connection.ReceiveFrameAsync();
224+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
225+
{
226+
// TODO: Remove when the regression is fixed.
227+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
228+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 0);
229+
230+
dataFrame = await h2Connection.ReceiveFrameAsync();
231+
}
138232
Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: true, length: 0);
139233

140234
// Http.Sys doesn't send a final GoAway unless we ignore the first one and send 200 additional streams.
@@ -152,6 +246,14 @@ await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
152246
});
153247

154248
dataFrame = await h2Connection.ReceiveFrameAsync();
249+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
250+
{
251+
// TODO: Remove when the regression is fixed.
252+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
253+
Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: false, length: 0);
254+
255+
dataFrame = await h2Connection.ReceiveFrameAsync();
256+
}
155257
Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: true, length: 0);
156258
}
157259

@@ -171,6 +273,14 @@ await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
171273
});
172274

173275
dataFrame = await h2Connection.ReceiveFrameAsync();
276+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
277+
{
278+
// TODO: Remove when the regression is fixed.
279+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
280+
Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: false, length: 0);
281+
282+
dataFrame = await h2Connection.ReceiveFrameAsync();
283+
}
174284
Http2Utilities.VerifyDataFrame(dataFrame, streamId, endOfStream: true, length: 0);
175285

176286
h2Connection.Logger.LogInformation("Connection stopped.");
@@ -180,7 +290,7 @@ await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
180290

181291
[ConditionalFact]
182292
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10, SkipReason = "Http2 requires Win10")]
183-
public async Task AppException_BeforeHeaders_500()
293+
public async Task AppException_BeforeResponseHeaders_500()
184294
{
185295
using var server = Utilities.CreateDynamicHttpsServer(out var address, httpContext =>
186296
{
@@ -202,6 +312,14 @@ await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
202312
});
203313

204314
var dataFrame = await h2Connection.ReceiveFrameAsync();
315+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
316+
{
317+
// TODO: Remove when the regression is fixed.
318+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
319+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 0);
320+
321+
dataFrame = await h2Connection.ReceiveFrameAsync();
322+
}
205323
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);
206324

207325
h2Connection.Logger.LogInformation("Connection stopped.");
@@ -266,8 +384,16 @@ await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
266384
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
267385
});
268386

269-
var resetFrame = await h2Connection.ReceiveFrameAsync();
270-
Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, Http2ErrorCode.INTERNAL_ERROR);
387+
var frame = await h2Connection.ReceiveFrameAsync();
388+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
389+
{
390+
// TODO: Remove when the regression is fixed.
391+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
392+
Http2Utilities.VerifyDataFrame(frame, 1, endOfStream: false, length: 0);
393+
394+
frame = await h2Connection.ReceiveFrameAsync();
395+
}
396+
Http2Utilities.VerifyResetFrame(frame, expectedStreamId: 1, Http2ErrorCode.INTERNAL_ERROR);
271397

272398
h2Connection.Logger.LogInformation("Connection stopped.");
273399
})
@@ -395,6 +521,9 @@ await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
395521
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
396522
});
397523

524+
var dataFrame = await h2Connection.ReceiveFrameAsync();
525+
Http2Utilities.VerifyDataFrame(dataFrame, expectedStreamId: 1, endOfStream: false, length: 0);
526+
398527
var resetFrame = await h2Connection.ReceiveFrameAsync();
399528
Http2Utilities.VerifyResetFrame(resetFrame, expectedStreamId: 1, expectedErrorCode: (Http2ErrorCode)1111);
400529

@@ -648,6 +777,14 @@ await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
648777
});
649778

650779
var dataFrame = await h2Connection.ReceiveFrameAsync();
780+
if (Environment.OSVersion.Version >= Win10_Regressed_DataFrame)
781+
{
782+
// TODO: Remove when the regression is fixed.
783+
// https://github.com/dotnet/aspnetcore/issues/23164#issuecomment-652646163
784+
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: false, length: 0);
785+
786+
dataFrame = await h2Connection.ReceiveFrameAsync();
787+
}
651788
Http2Utilities.VerifyDataFrame(dataFrame, 1, endOfStream: true, length: 0);
652789

653790
var resetFrame = await h2Connection.ReceiveFrameAsync();

0 commit comments

Comments
 (0)