Skip to content

Commit 90030f7

Browse files
committed
CI test
1 parent 35437dd commit 90030f7

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

eng/test-configuration.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"defaultOnFailure": "fail",
44
"localRerunCount": 2,
55
"retryOnRules": [
6-
{ "testAssembly": { "wildcard": "System.Net.*" } },
76
{ "failureMessage": { "regex": ".*Timed out after .* waiting for the browser to be ready.*" } },
87
{ "failureMessage": { "regex": "System.IO.IOException : Process for .*chrome.*unexpectedly exited.* during startup" } }
98
]

src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs

+42-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using System.Diagnostics;
55
using System.IO;
66
using System.Net.Sockets;
7+
using System.Linq;
78
using System.Net.Test.Common;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using Microsoft.DotNet.RemoteExecutor;
1112
using Xunit;
1213
using Xunit.Abstractions;
14+
using TestUtilities;
1315

1416
namespace System.Net.Http.Functional.Tests
1517
{
@@ -107,7 +109,21 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
107109
options: new GenericLoopbackOptions() { UseSsl = false });
108110
}
109111

110-
[OuterLoop]
112+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
113+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
114+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
115+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
116+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection6() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
117+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection7() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
118+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection8() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
119+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection9() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
120+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection10() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
121+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection11() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
122+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection12() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
123+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection13() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
124+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection14() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
125+
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection15() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
126+
111127
[Theory]
112128
[InlineData(true)]
113129
[InlineData(false)]
@@ -125,18 +141,19 @@ public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSu
125141
return;
126142
}
127143

144+
using var listener = new TestEventListener(_output, TestEventListener.NetworkingEvents);
145+
128146
await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
129147
{
130148
int connectCount = 0;
131149

132-
TaskCompletionSource tcsFirstConnectionInitiated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
133-
TaskCompletionSource tcsFirstRequestCanceled = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
150+
var tcsFirstConnectionInitiated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
151+
var tcsFirstRequestCanceled = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
134152

135-
using (var handler = CreateHttpClientHandler(allowAllCertificates: true))
136-
using (var client = CreateHttpClient(handler))
153+
using (HttpClientHandler handler = CreateHttpClientHandler())
154+
using (HttpClient client = CreateHttpClient(handler))
137155
{
138-
var socketsHandler = GetUnderlyingSocketsHttpHandler(handler);
139-
socketsHandler.ConnectCallback = async (context, token) =>
156+
GetUnderlyingSocketsHttpHandler(handler).ConnectCallback = async (context, token) =>
140157
{
141158
// Note we force serialization of connection creation by waiting on tcsFirstConnectionInitiated below,
142159
// so we don't need to worry about concurrent access to connectCount.
@@ -145,6 +162,8 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
145162

146163
Assert.True(connectCount <= 2);
147164

165+
_output.WriteLine($"Connection count {connectCount}");
166+
148167
if (isFirstConnection)
149168
{
150169
tcsFirstConnectionInitiated.SetResult();
@@ -157,6 +176,8 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
157176
// Wait until first request is cancelled and has completed
158177
await tcsFirstRequestCanceled.Task;
159178

179+
_output.WriteLine($"After tcsFirstRequestCanceled {isFirstConnection}");
180+
160181
if (isFirstConnection)
161182
{
162183
// Fail the first connection attempt
@@ -170,27 +191,34 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
170191
};
171192

172193
using CancellationTokenSource cts = new CancellationTokenSource();
173-
Task<HttpResponseMessage> t1 = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri) { Version = UseVersion, VersionPolicy = HttpVersionPolicy.RequestVersionExact }, cts.Token);
194+
Task<HttpResponseMessage> t1 = client.SendAsync(CreateRequest(HttpMethod.Get, uri, UseVersion, exactVersion: true), cts.Token);
195+
_output.WriteLine("t1");
174196

175197
// Wait for the connection attempt to be initiated before we send the second request, to avoid races in connection creation
176-
await tcsFirstConnectionInitiated.Task;
177-
Task<HttpResponseMessage> t2 = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri) { Version = UseVersion, VersionPolicy = HttpVersionPolicy.RequestVersionExact }, default);
198+
await tcsFirstConnectionInitiated.Task.WaitAsync(TestHelper.PassingTestTimeout);
199+
Task<HttpResponseMessage> t2 = client.SendAsync(CreateRequest(HttpMethod.Get, uri, UseVersion, exactVersion: true), CancellationToken.None);
200+
_output.WriteLine("t2");
178201

179202
// Cancel the first message and wait for it to complete
180203
cts.Cancel();
181-
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t1);
204+
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t1).WaitAsync(TestHelper.PassingTestTimeout);
205+
_output.WriteLine("ThrowsAnyAsync");
182206

183207
// Signal connections to proceed
184208
tcsFirstRequestCanceled.SetResult();
185209

186210
// Second request should succeed, even though the first connection failed
187-
HttpResponseMessage resp2 = await t2;
211+
HttpResponseMessage resp2 = await t2.WaitAsync(TestHelper.PassingTestTimeout);
212+
_output.WriteLine("resp2");
188213
Assert.Equal(HttpStatusCode.OK, resp2.StatusCode);
189-
Assert.Equal("Hello world", await resp2.Content.ReadAsStringAsync());
214+
Assert.Equal("Hello world", await resp2.Content.ReadAsStringAsync().WaitAsync(TestHelper.PassingTestTimeout));
215+
216+
Assert.True(connectCount == 2);
190217
}
191218
}, async server =>
192219
{
193-
await server.AcceptConnectionSendResponseAndCloseAsync(content: "Hello world");
220+
await server.HandleRequestAsync(content: "Hello world").WaitAsync(TestHelper.PassingTestTimeout);
221+
_output.WriteLine("Server done");
194222
},
195223
options: new GenericLoopbackOptions() { UseSsl = useSsl });
196224
}

0 commit comments

Comments
 (0)