Skip to content

Commit ac1f96f

Browse files
committed
Fix System.Net.Http.Functional.Tests.SocketsHttpHandlerTest_HttpClientHandlerTest_Http3.ReadAsStreamAsync_Cancellation failure
1 parent e8a5dce commit ac1f96f

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs

+26-21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Net.Http.Headers;
88
using System.Net.Sockets;
9+
using System.Net.Quic;
910
using System.Net.Test.Common;
1011
using System.Security.Authentication;
1112
using System.Security.Cryptography;
@@ -267,7 +268,7 @@ await LoopbackServer.CreateClientAndServerAsync(async proxyUri =>
267268
public static IEnumerable<object[]> SecureAndNonSecure_IPBasedUri_MemberData() =>
268269
from address in new[] { IPAddress.Loopback, IPAddress.IPv6Loopback }
269270
from useSsl in BoolValues
270-
// we could not create SslStream in browser, [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
271+
// we could not create SslStream in browser, [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
271272
where PlatformDetection.IsNotBrowser || !useSsl
272273
select new object[] { address, useSsl };
273274

@@ -877,8 +878,8 @@ await LoopbackServer.CreateClientAndServerAsync(async url =>
877878
"\r\n" +
878879
"5\r\n" +
879880
"hello" + // missing \r\n terminator
880-
//"5\r\n" +
881-
//"world" + // missing \r\n terminator
881+
//"5\r\n" +
882+
//"world" + // missing \r\n terminator
882883
"0\r\n" +
883884
"\r\n"));
884885
}
@@ -1091,7 +1092,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
10911092
if (PlatformDetection.IsBrowser)
10921093
{
10931094
#if !NETFRAMEWORK
1094-
if(slowChunks)
1095+
if (slowChunks)
10951096
{
10961097
Assert.Equal(1, await responseStream.ReadAsync(new Memory<byte>(buffer2)));
10971098
Assert.Equal((byte)'h', buffer2[0]);
@@ -1201,7 +1202,7 @@ await server.AcceptConnectionAsync(async connection =>
12011202
{
12021203
case true:
12031204
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] { new HttpHeaderData("Transfer-Encoding", "chunked") }, isFinal: false);
1204-
if(PlatformDetection.IsBrowser && slowChunks)
1205+
if (PlatformDetection.IsBrowser && slowChunks)
12051206
{
12061207
await connection.SendResponseBodyAsync("1\r\nh\r\n", false);
12071208
await tcs.Task;
@@ -1216,12 +1217,12 @@ await server.AcceptConnectionAsync(async connection =>
12161217
break;
12171218

12181219
case false:
1219-
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] { new HttpHeaderData("Content-Length", "11")}, content: "hello world");
1220+
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] { new HttpHeaderData("Content-Length", "11") }, content: "hello world");
12201221
break;
12211222

12221223
case null:
12231224
// This inject Content-Length header with null value to hint Loopback code to not include one automatically.
1224-
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] { new HttpHeaderData("Content-Length", null)}, isFinal: false);
1225+
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] { new HttpHeaderData("Content-Length", null) }, isFinal: false);
12251226
await connection.SendResponseBodyAsync("hello world");
12261227
break;
12271228
}
@@ -1396,6 +1397,10 @@ await server.AcceptConnectionAsync(async connection =>
13961397
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] { new HttpHeaderData("Transfer-Encoding", "chunked") }, isFinal: false);
13971398
await connection.SendResponseBodyAsync("1\r\nh\r\n", false);
13981399
}
1400+
catch (QuicException ex) when (ex.ApplicationErrorCode == 0x10c /*H3_REQUEST_CANCELLED*/)
1401+
{
1402+
// The request was cancelled before we sent the body, ignore
1403+
}
13991404
catch (IOException ex)
14001405
{
14011406
// when testing in the browser, we are using the WebSocket for the loopback
@@ -1450,10 +1455,10 @@ await LoopbackServerFactory.CreateServerAsync(async (server3, url3) =>
14501455
Task serverTask3 = server3.AcceptConnectionAsync(async connection3 =>
14511456
{
14521457
await connection3.ReadRequestDataAsync();
1453-
await connection3.SendResponseAsync(HttpStatusCode.OK, new HttpHeaderData[] { new HttpHeaderData("Content-Length", "20") }, isFinal : false);
1454-
await connection3.SendResponseBodyAsync("1234567890", isFinal : false);
1458+
await connection3.SendResponseAsync(HttpStatusCode.OK, new HttpHeaderData[] { new HttpHeaderData("Content-Length", "20") }, isFinal: false);
1459+
await connection3.SendResponseBodyAsync("1234567890", isFinal: false);
14551460
await unblockServers.Task;
1456-
await connection3.SendResponseBodyAsync("1234567890", isFinal : true);
1461+
await connection3.SendResponseBodyAsync("1234567890", isFinal: true);
14571462
});
14581463

14591464
// Make three requests
@@ -1527,7 +1532,7 @@ public async Task GetAsync_UnicodeHostName_SuccessStatusCodeInResponse()
15271532
}
15281533
}
15291534

1530-
#region Post Methods Tests
1535+
#region Post Methods Tests
15311536

15321537
[Fact]
15331538
[SkipOnPlatform(TestPlatforms.Browser, "ExpectContinue not supported on Browser")]
@@ -1571,13 +1576,13 @@ await server.AcceptConnectionAsync(async connection =>
15711576

15721577
public static IEnumerable<object[]> Interim1xxStatusCode()
15731578
{
1574-
yield return new object[] { (HttpStatusCode) 100 }; // 100 Continue.
1579+
yield return new object[] { (HttpStatusCode)100 }; // 100 Continue.
15751580
// 101 SwitchingProtocols will be treated as a final status code.
1576-
yield return new object[] { (HttpStatusCode) 102 }; // 102 Processing.
1577-
yield return new object[] { (HttpStatusCode) 103 }; // 103 EarlyHints.
1578-
yield return new object[] { (HttpStatusCode) 150 };
1579-
yield return new object[] { (HttpStatusCode) 180 };
1580-
yield return new object[] { (HttpStatusCode) 199 };
1581+
yield return new object[] { (HttpStatusCode)102 }; // 102 Processing.
1582+
yield return new object[] { (HttpStatusCode)103 }; // 103 EarlyHints.
1583+
yield return new object[] { (HttpStatusCode)150 };
1584+
yield return new object[] { (HttpStatusCode)180 };
1585+
yield return new object[] { (HttpStatusCode)199 };
15811586
}
15821587

15831588
[Theory]
@@ -1638,7 +1643,7 @@ await server.AcceptConnectionAsync(async connection =>
16381643
new HttpHeaderData("Content-type", "text/xml"),
16391644
new HttpHeaderData("Set-Cookie", SetCookieIgnored1)}, isFinal: false);
16401645

1641-
await connection.SendResponseAsync(responseStatusCode, headers: new HttpHeaderData[] {
1646+
await connection.SendResponseAsync(responseStatusCode, headers: new HttpHeaderData[] {
16421647
new HttpHeaderData("Cookie", "ignore_cookie=choco2"),
16431648
new HttpHeaderData("Content-type", "text/plain"),
16441649
new HttpHeaderData("Set-Cookie", SetCookieIgnored2)}, isFinal: false);
@@ -1742,7 +1747,7 @@ await server.AcceptConnectionAsync(async connection =>
17421747
{
17431748
await connection.ReadRequestDataAsync(readBody: false);
17441749
// Send multiple 100-Continue responses.
1745-
for (int count = 0 ; count < 4; count++)
1750+
for (int count = 0; count < 4; count++)
17461751
{
17471752
await connection.SendResponseAsync(HttpStatusCode.Continue, isFinal: false);
17481753
}
@@ -1846,7 +1851,7 @@ await server.AcceptConnectionAsync(async connection =>
18461851
{
18471852
await connection.ReadRequestDataAsync(readBody: false);
18481853

1849-
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] {new HttpHeaderData("Content-Length", $"{ResponseString.Length}")}, isFinal : false);
1854+
await connection.SendResponseAsync(HttpStatusCode.OK, headers: new HttpHeaderData[] { new HttpHeaderData("Content-Length", $"{ResponseString.Length}") }, isFinal: false);
18501855

18511856
byte[] body = await connection.ReadRequestBodyAsync();
18521857
Assert.Equal(RequestString, Encoding.ASCII.GetString(body));
@@ -2127,7 +2132,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, rootUrl) =>
21272132
}
21282133
});
21292134
}
2130-
#endregion
2135+
#endregion
21312136

21322137
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowserDomSupported))]
21332138
public async Task GetAsync_InvalidUrl_ExpectedExceptionThrown()

0 commit comments

Comments
 (0)