Skip to content

Commit 4f82fe7

Browse files
authored
[HTTP] H/3 fix test closing server connection prematurely (#117458)
* Add synchronization into the test * Feedback
1 parent d55770b commit 4f82fe7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,7 @@ public async Task SendAsync_InvalidRequestUri_Throws()
21732173
public async Task SendAsync_RequestWithDangerousControlHeaderValue_ThrowsHttpRequestException(char dangerousChar, HeaderType headerType)
21742174
{
21752175
TaskCompletionSource<bool> acceptConnection = new TaskCompletionSource<bool>();
2176+
SemaphoreSlim clientFinished = new SemaphoreSlim(0);
21762177

21772178
await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
21782179
{
@@ -2216,6 +2217,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
22162217
// WinHTTP validates the input before opening connection whereas SocketsHttpHandler opens connection first and validates only when writing to the wire.
22172218
acceptConnection.SetResult(!IsWinHttpHandler);
22182219
var ex = await Assert.ThrowsAnyAsync<Exception>(() => client.SendAsync(request));
2220+
clientFinished.Release();
22192221
var hrex = Assert.IsType<HttpRequestException>(ex);
22202222
if (IsWinHttpHandler)
22212223
{
@@ -2231,7 +2233,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
22312233
{
22322234
if (await acceptConnection.Task)
22332235
{
2234-
await IgnoreExceptions(server.AcceptConnectionAsync(c => Task.CompletedTask));
2236+
await IgnoreExceptions(() => server.AcceptConnectionAsync(_ => clientFinished.WaitAsync(TestHelper.PassingTestTimeout)));
22352237
}
22362238
});
22372239
}

0 commit comments

Comments
 (0)