Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ca07fd9

Browse files
authored
Fix sporadically failing PreAuthenticate test on WinHttpHandler (#28226)
The PreAuthenticate_FirstRequestNoHeader_SecondRequestVariousStatusCodes_ThirdRequestPreauthenticates tests a bunch of status codes, some of which are sporadically failing in CI with WinHttpHandler. According to the RFC, several of these status codes require that there not be a response body, but the test is sending one, and it would seem there are then race conditions that are causing WinHttp to fail here and there for these status codes, e.g. 204 and 304. This just fixes the test to not send a body.
1 parent 9ae8e66 commit ca07fd9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Authentication.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,26 +326,26 @@ await LoopbackServer.CreateClientAndServerAsync(async uri =>
326326
using (var client = new HttpClient(handler))
327327
{
328328
client.DefaultRequestHeaders.ConnectionClose = true; // for simplicity of not needing to know every handler's pooling policy
329-
handler.PreAuthenticate = true;
329+
handler.PreAuthenticate = true;
330330
handler.Credentials = s_credentials;
331331
client.DefaultRequestHeaders.ExpectContinue = false;
332332

333333
using (HttpResponseMessage resp = await client.GetAsync(uri))
334334
{
335335
Assert.Equal(statusCode, resp.StatusCode);
336336
}
337-
Assert.Equal("hello world 2", await client.GetStringAsync(uri));
337+
Assert.Equal("hello world", await client.GetStringAsync(uri));
338338
}
339339
},
340340
async server =>
341341
{
342342
List<string> headers = await server.AcceptConnectionSendResponseAndCloseAsync(HttpStatusCode.Unauthorized, AuthResponse);
343343
Assert.All(headers, header => Assert.DoesNotContain("Authorization", header));
344344

345-
headers = await server.AcceptConnectionSendResponseAndCloseAsync(statusCode, content: "hello world 1");
345+
headers = await server.AcceptConnectionSendResponseAndCloseAsync(statusCode);
346346
Assert.Contains(headers, header => header.Contains("Authorization"));
347347

348-
headers = await server.AcceptConnectionSendResponseAndCloseAsync(HttpStatusCode.OK, content: "hello world 2");
348+
headers = await server.AcceptConnectionSendResponseAndCloseAsync(HttpStatusCode.OK, content: "hello world");
349349
Assert.Contains(headers, header => header.Contains("Authorization"));
350350
});
351351
}

0 commit comments

Comments
 (0)