Skip to content

Commit 08d0bcd

Browse files
committed
Add synchronization into the test
1 parent 2de958d commit 08d0bcd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 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
if (IsWinHttpHandler)
22202222
{
22212223
var fex = Assert.IsType<FormatException>(ex);
@@ -2232,7 +2234,13 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
22322234
{
22332235
if (await acceptConnection.Task)
22342236
{
2235-
await IgnoreExceptions(server.AcceptConnectionAsync(c => Task.CompletedTask));
2237+
await IgnoreExceptions(async () =>
2238+
{
2239+
await server.AcceptConnectionAsync(async _ =>
2240+
{
2241+
await clientFinished.WaitAsync(TestHelper.PassingTestTimeout);
2242+
});
2243+
});
22362244
}
22372245
});
22382246
}

0 commit comments

Comments
 (0)