diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs index 6fe645ce6b4513..5ce36c2a7e8faf 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs @@ -1591,7 +1591,7 @@ await GetFactoryForVersion(UseVersion).CreateServerAsync(async (server, uri) => }); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] public async Task Http3_WaitForConnection_RecordedWhenWaitingForStream() { if (UseVersion != HttpVersion30 || !TestAsync) @@ -1599,67 +1599,71 @@ public async Task Http3_WaitForConnection_RecordedWhenWaitingForStream() throw new SkipTestException("This test is specific to async HTTP/3 runs."); } - using Http3LoopbackServer server = CreateHttp3LoopbackServer(new Http3Options() { MaxInboundBidirectionalStreams = 1 }); + await RemoteExecutor.Invoke(RunTest).DisposeAsync(); + static async Task RunTest() + { + using Http3LoopbackServer server = CreateHttp3LoopbackServer(new Http3Options() { MaxInboundBidirectionalStreams = 1 }); - TaskCompletionSource stream1Created = new(); - TaskCompletionSource allRequestsWaiting = new(); + TaskCompletionSource stream1Created = new(); + TaskCompletionSource allRequestsWaiting = new(); - Task serverTask = Task.Run(async () => - { - await using Http3LoopbackConnection connection = (Http3LoopbackConnection)await server.EstablishGenericConnectionAsync(); - Http3LoopbackStream stream1 = await connection.AcceptRequestStreamAsync(); - stream1Created.SetResult(); + Task serverTask = Task.Run(async () => + { + await using Http3LoopbackConnection connection = (Http3LoopbackConnection)await server.EstablishGenericConnectionAsync(); + Http3LoopbackStream stream1 = await connection.AcceptRequestStreamAsync(); + stream1Created.SetResult(); - await allRequestsWaiting.Task; - await stream1.HandleRequestAsync(); - await stream1.DisposeAsync(); + await allRequestsWaiting.Task; + await stream1.HandleRequestAsync(); + await stream1.DisposeAsync(); - Http3LoopbackStream stream2 = await connection.AcceptRequestStreamAsync(); - await stream2.HandleRequestAsync(); - await stream2.DisposeAsync(); + Http3LoopbackStream stream2 = await connection.AcceptRequestStreamAsync(); + await stream2.HandleRequestAsync(); + await stream2.DisposeAsync(); - Http3LoopbackStream stream3 = await connection.AcceptRequestStreamAsync(); - await stream3.HandleRequestAsync(); - await stream3.DisposeAsync(); - }); + Http3LoopbackStream stream3 = await connection.AcceptRequestStreamAsync(); + await stream3.HandleRequestAsync(); + await stream3.DisposeAsync(); + }); - Task clientTask = Task.Run(async () => - { - using Activity parentActivity = new Activity("parent").Start(); - using ActivityRecorder requestRecorder = new("System.Net.Http", "System.Net.Http.HttpRequestOut") - { - ExpectedParent = parentActivity - }; - using ActivityRecorder waitForConnectionRecorder = new("Experimental.System.Net.Http.Connections", "Experimental.System.Net.Http.Connections.WaitForConnection") - { - VerifyParent = false - }; - waitForConnectionRecorder.OnStarted = a => + Task clientTask = Task.Run(async () => { - if (waitForConnectionRecorder.Started == 3) + using Activity parentActivity = new Activity("parent").Start(); + using ActivityRecorder requestRecorder = new("System.Net.Http", "System.Net.Http.HttpRequestOut") { - allRequestsWaiting.SetResult(); - } - }; + ExpectedParent = parentActivity + }; + using ActivityRecorder waitForConnectionRecorder = new("Experimental.System.Net.Http.Connections", "Experimental.System.Net.Http.Connections.WaitForConnection") + { + VerifyParent = false + }; + waitForConnectionRecorder.OnStarted = a => + { + if (waitForConnectionRecorder.Started == 3) + { + allRequestsWaiting.SetResult(); + } + }; - SocketsHttpHandler handler = CreateSocketsHttpHandler(allowAllCertificates: true); - using HttpClient client = new HttpClient(CreateSocketsHttpHandler(allowAllCertificates: true)) - { - DefaultRequestVersion = HttpVersion30, - DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact - }; + SocketsHttpHandler handler = CreateSocketsHttpHandler(allowAllCertificates: true); + using HttpClient client = new HttpClient(CreateSocketsHttpHandler(allowAllCertificates: true)) + { + DefaultRequestVersion = HttpVersion30, + DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact + }; - Task request1Task = client.GetAsync(server.Address); - await stream1Created.Task; + Task request1Task = client.GetAsync(server.Address); + await stream1Created.Task; - Task request2Task = client.GetAsync(server.Address); - Task request3Task = client.GetAsync(server.Address); + Task request2Task = client.GetAsync(server.Address); + Task request3Task = client.GetAsync(server.Address); - await new Task[] { request1Task, request2Task, request3Task }.WhenAllOrAnyFailed(30_000); - Assert.Equal(3, waitForConnectionRecorder.Stopped); - }); + await new Task[] { request1Task, request2Task, request3Task }.WhenAllOrAnyFailed(30_000); + Assert.Equal(3, waitForConnectionRecorder.Stopped); + }); - await new Task[] { serverTask, clientTask }.WhenAllOrAnyFailed(30_000); + await new Task[] { serverTask, clientTask }.WhenAllOrAnyFailed(30_000); + } } private static T GetProperty(object obj, string propertyName) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs index 088e57294d54b2..220e6706fcf168 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTestBase.SocketsHttpHandler.cs @@ -63,7 +63,7 @@ protected static HttpClientHandler CreateHttpClientHandler(Version useVersion = protected static SocketsHttpHandler CreateSocketsHttpHandler(bool allowAllCertificates) => TestHelper.CreateSocketsHttpHandler(allowAllCertificates); - protected Http3LoopbackServer CreateHttp3LoopbackServer(Http3Options options = default) + protected static Http3LoopbackServer CreateHttp3LoopbackServer(Http3Options options = default) { return new Http3LoopbackServer(options); }