Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI test #103646

Closed
wants to merge 1 commit into from
Closed

CI test #103646

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void Associate(object? thisOrContextObject, object first, object s
[Event(AssociateEventId, Level = EventLevel.Informational, Keywords = Keywords.Default, Message = "[{2}]<-->[{3}]")]
private void Associate(string thisOrContextObject, string? memberName, string first, string second)
{
Debug.Assert(IsEnabled());
//Debug.Assert(IsEnabled());
WriteEvent(AssociateEventId, thisOrContextObject, memberName ?? MissingMember, first, second);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void Info(object? thisOrContextObject, object? message, [CallerMem
[Event(InfoEventId, Level = EventLevel.Informational, Keywords = Keywords.Default)]
private void Info(string thisOrContextObject, string? memberName, string? message)
{
Debug.Assert(IsEnabled());
//Debug.Assert(IsEnabled());
WriteEvent(InfoEventId, thisOrContextObject, memberName ?? MissingMember, message);
}
#endregion
Expand All @@ -102,7 +102,7 @@ public static void Error(object? thisOrContextObject, object message, [CallerMem
[Event(ErrorEventId, Level = EventLevel.Error, Keywords = Keywords.Default)]
private void ErrorMessage(string thisOrContextObject, string? memberName, string? message)
{
Debug.Assert(IsEnabled());
//Debug.Assert(IsEnabled());
WriteEvent(ErrorEventId, thisOrContextObject, memberName ?? MissingMember, message);
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace System.Net.Http.Functional.Tests
{
[ActiveIssue("Foo")]
public abstract class DiagnosticsTest : HttpClientHandlerTestBase
{
private const string EnableActivityPropagationEnvironmentVariableSettingName = "DOTNET_SYSTEM_NET_HTTP_ENABLEACTIVITYPROPAGATION";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
using Xunit.Abstractions;
using TestUtilities;

namespace System.Net.Http.Functional.Tests
{
Expand All @@ -18,6 +19,11 @@ public abstract class SocketsHttpHandler_Cancellation_Test : HttpClientHandler_C
{
protected SocketsHttpHandler_Cancellation_Test(ITestOutputHelper output) : base(output) { }

[Fact] public async Task ValidateConnectTimeout2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact] public async Task ValidateConnectTimeout3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact][OuterLoop] public async Task ValidateConnectTimeout4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact][OuterLoop] public async Task ValidateConnectTimeout5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);

private async Task ValidateConnectTimeout(HttpMessageInvoker invoker, Uri uri, int minElapsed, int maxElapsed)
{
var sw = Stopwatch.StartNew();
Expand Down Expand Up @@ -81,6 +87,11 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
options: new GenericLoopbackOptions() { UseSsl = useSsl });
}

[Fact] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact][OuterLoop] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact][OuterLoop] public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);

[OuterLoop]
[Fact]
public async Task ConnectTimeout_PlaintextStreamFilterTimesOut_Throws()
Expand All @@ -107,36 +118,35 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
options: new GenericLoopbackOptions() { UseSsl = false });
}

[OuterLoop]
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);

[Fact][OuterLoop] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact][OuterLoop] public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(bool useSsl)
{
if (UseVersion == HttpVersion.Version30)
if (UseVersion.Major != 1 || !TestAsync || !useSsl)
{
// HTTP3 does not support ConnectCallback
return;
}

if (!TestAsync)
{
// Test relies on ordering of async operations, so we can't test the sync case
return;
}
using var listener = new TestEventListener(_output, TestEventListener.NetworkingEvents);

await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
{
int connectCount = 0;

TaskCompletionSource tcsFirstConnectionInitiated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
TaskCompletionSource tcsFirstRequestCanceled = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var tcsFirstConnectionInitiated = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var tcsFirstRequestCanceled = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

using (var handler = CreateHttpClientHandler(allowAllCertificates: true))
using (var client = CreateHttpClient(handler))
using (HttpClientHandler handler = CreateHttpClientHandler())
using (HttpClient client = CreateHttpClient(handler))
{
var socketsHandler = GetUnderlyingSocketsHttpHandler(handler);
socketsHandler.ConnectCallback = async (context, token) =>
GetUnderlyingSocketsHttpHandler(handler).ConnectCallback = async (context, token) =>
{
// Note we force serialization of connection creation by waiting on tcsFirstConnectionInitiated below,
// so we don't need to worry about concurrent access to connectCount.
Expand All @@ -145,6 +155,8 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>

Assert.True(connectCount <= 2);

_output.WriteLine($"Connection count {connectCount}");

if (isFirstConnection)
{
tcsFirstConnectionInitiated.SetResult();
Expand All @@ -157,6 +169,8 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
// Wait until first request is cancelled and has completed
await tcsFirstRequestCanceled.Task;

_output.WriteLine($"After tcsFirstRequestCanceled {isFirstConnection}");

if (isFirstConnection)
{
// Fail the first connection attempt
Expand All @@ -170,27 +184,34 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
};

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

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

// Cancel the first message and wait for it to complete
cts.Cancel();
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t1);
_output.WriteLine("ThrowsAnyAsync");

// Signal connections to proceed
tcsFirstRequestCanceled.SetResult();

// Second request should succeed, even though the first connection failed
HttpResponseMessage resp2 = await t2;
_output.WriteLine("resp2");
Assert.Equal(HttpStatusCode.OK, resp2.StatusCode);
Assert.Equal("Hello world", await resp2.Content.ReadAsStringAsync());

Assert.True(connectCount == 2);
}
}, async server =>
{
await server.AcceptConnectionSendResponseAndCloseAsync(content: "Hello world");
await server.HandleRequestAsync(content: "Hello world");
_output.WriteLine("Server done");
},
options: new GenericLoopbackOptions() { UseSsl = useSsl });
}
Expand Down Expand Up @@ -393,6 +414,11 @@ await RemoteExecutor.Invoke(static async (versionString, timoutStr) =>
}, UseVersion.ToString(), timeout.ToString()).DisposeAsync();
}

[Fact] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled2() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled3() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact] [OuterLoop] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled4() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);
[Fact] [OuterLoop] public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled5() => await ConnectionFailure_AfterInitialRequestCancelled_SecondRequestSucceedsOnNewConnection(true);

private sealed class SetTcsContent : StreamContent
{
private readonly TaskCompletionSource<bool> _tcs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void Error(Exception exception, [CallerMemberName] string? memberN
[Event(ErrorEventId, Level = EventLevel.Error)]
private void ErrorMessage(string memberName, string message)
{
Debug.Assert(IsEnabled());
//Debug.Assert(IsEnabled());
WriteEvent(ErrorEventId, memberName, message);
}
}
Expand Down
Loading