Skip to content

Commit 1e38de0

Browse files
authored
[H/3] Fix test closing connection too fast (#112691)
* Fix test closing connection too fast * Same fix for similar test
1 parent 3232b44 commit 1e38de0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
7373
[InlineData(15)]
7474
public async Task LargeSingleHeader_ThrowsException(int maxResponseHeadersLength)
7575
{
76+
var semaphore = new SemaphoreSlim(0);
7677
using HttpClientHandler handler = CreateHttpClientHandler();
7778
handler.MaxResponseHeadersLength = maxResponseHeadersLength;
7879

@@ -85,6 +86,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
8586
{
8687
Assert.Contains((handler.MaxResponseHeadersLength * 1024).ToString(), e.ToString());
8788
}
89+
await semaphore.WaitAsync();
8890
},
8991
async server =>
9092
{
@@ -97,6 +99,10 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
9799
#if !WINHTTPHANDLER_TEST
98100
catch (QuicException ex) when (ex.QuicError == QuicError.StreamAborted && ex.ApplicationErrorCode == Http3ExcessiveLoad) {}
99101
#endif
102+
finally
103+
{
104+
semaphore.Release();
105+
}
100106
});
101107
}
102108

@@ -108,6 +114,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
108114
[InlineData(int.MaxValue / 800, 100 * 1024)] // Capped at int.MaxValue
109115
public async Task ThresholdExceeded_ThrowsException(int? maxResponseHeadersLength, int headersLengthEstimate)
110116
{
117+
var semaphore = new SemaphoreSlim(0);
111118
await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
112119
{
113120
using HttpClientHandler handler = CreateHttpClientHandler();
@@ -131,6 +138,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
131138
Assert.Contains((handler.MaxResponseHeadersLength * 1024).ToString(), e.ToString());
132139
}
133140
}
141+
await semaphore.WaitAsync();
134142
},
135143
async server =>
136144
{
@@ -149,6 +157,10 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
149157
#if !WINHTTPHANDLER_TEST
150158
catch (QuicException ex) when (ex.QuicError == QuicError.StreamAborted && ex.ApplicationErrorCode == Http3ExcessiveLoad) {}
151159
#endif
160+
finally
161+
{
162+
semaphore.Release();
163+
}
152164
});
153165
}
154166
}

0 commit comments

Comments
 (0)