diff --git a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs index 5635b753a5f6c..581bc018a1983 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackConnection.cs @@ -75,7 +75,7 @@ public override async ValueTask DisposeAsync() // Dispose the connection // If we already waited for graceful shutdown from the client, then the connection is already closed and this will simply release the handle. // If not, then this will silently abort the connection. - await _connection.DisposeAsync(); + await _connection.DisposeAsync().ConfigureAwait(false); // Dispose control streams so that we release their handles too. if (_inboundControlStream is not null) @@ -92,12 +92,12 @@ public override async ValueTask DisposeAsync() public async ValueTask OpenUnidirectionalStreamAsync() { - return new Http3LoopbackStream(await _connection.OpenOutboundStreamAsync(QuicStreamType.Unidirectional)); + return new Http3LoopbackStream(await _connection.OpenOutboundStreamAsync(QuicStreamType.Unidirectional).ConfigureAwait(false)); } public async ValueTask OpenBidirectionalStreamAsync() { - return new Http3LoopbackStream(await _connection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional)); + return new Http3LoopbackStream(await _connection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional).ConfigureAwait(false)); } public static int GetRequestId(QuicStream stream) @@ -141,10 +141,10 @@ async Task EnsureControlStreamAcceptedInternalAsync() _delayedStreams.Enqueue(quicStream); } - long? streamType = await controlStream.ReadIntegerAsync(); + long? streamType = await controlStream.ReadIntegerAsync().ConfigureAwait(false); Assert.Equal(Http3LoopbackStream.ControlStream, streamType); - List<(long settingId, long settingValue)> settings = await controlStream.ReadSettingsAsync(); + List<(long settingId, long settingValue)> settings = await controlStream.ReadSettingsAsync().ConfigureAwait(false); (long settingId, long settingValue) = Assert.Single(settings); Assert.Equal(Http3LoopbackStream.MaxHeaderListSize, settingId); @@ -177,7 +177,7 @@ public async Task AcceptRequestStreamAsync() public async Task<(Http3LoopbackStream clientControlStream, Http3LoopbackStream requestStream)> AcceptControlAndRequestStreamAsync() { - Http3LoopbackStream requestStream = await AcceptRequestStreamAsync(); + Http3LoopbackStream requestStream = await AcceptRequestStreamAsync().ConfigureAwait(false); Http3LoopbackStream controlStream = _inboundControlStream; return (controlStream, requestStream); @@ -185,9 +185,9 @@ public async Task AcceptRequestStreamAsync() public async Task EstablishControlStreamAsync(SettingsEntry[] settingsEntries) { - _outboundControlStream = await OpenUnidirectionalStreamAsync(); - await _outboundControlStream.SendUnidirectionalStreamTypeAsync(Http3LoopbackStream.ControlStream); - await _outboundControlStream.SendSettingsFrameAsync(settingsEntries); + _outboundControlStream = await OpenUnidirectionalStreamAsync().ConfigureAwait(false); + await _outboundControlStream.SendUnidirectionalStreamTypeAsync(Http3LoopbackStream.ControlStream).ConfigureAwait(false); + await _outboundControlStream.SendSettingsFrameAsync(settingsEntries).ConfigureAwait(false); } public async Task DisposeCurrentStream() @@ -213,7 +213,7 @@ public override async Task ReadRequestDataAsync(bool readBody = public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "", bool isFinal = true) { - await _currentStream.SendResponseAsync(statusCode, headers, content, isFinal); + await _currentStream.SendResponseAsync(statusCode, headers, content, isFinal).ConfigureAwait(false); if (isFinal) { await DisposeCurrentStream().ConfigureAwait(false); @@ -222,7 +222,7 @@ public override async Task SendResponseAsync(HttpStatusCode statusCode = HttpSta public override async Task SendResponseBodyAsync(byte[] content, bool isFinal = true) { - await _currentStream.SendResponseBodyAsync(content, isFinal); + await _currentStream.SendResponseBodyAsync(content, isFinal).ConfigureAwait(false); if (isFinal) { await DisposeCurrentStream().ConfigureAwait(false); @@ -249,11 +249,11 @@ public override async Task HandleRequestAsync(HttpStatusCode st // So, send a GOAWAY frame now so the client won't inadvertantly try to reuse the connection. // Note that in HTTP3 (unlike HTTP2) there is no strict ordering between the GOAWAY and the response below; // so the client may race in processing them and we need to handle this. - await _outboundControlStream.SendGoAwayFrameAsync(stream.StreamId + 4); + await _outboundControlStream.SendGoAwayFrameAsync(stream.StreamId + 4).ConfigureAwait(false); await stream.SendResponseAsync(statusCode, headers, content).ConfigureAwait(false); - await WaitForClientDisconnectAsync(); + await WaitForClientDisconnectAsync().ConfigureAwait(false); return request; } @@ -263,7 +263,7 @@ public async Task ShutdownAsync(bool failCurrentRequest = false) try { long firstInvalidStreamId = failCurrentRequest ? _currentStreamId : _currentStreamId + 4; - await _outboundControlStream.SendGoAwayFrameAsync(firstInvalidStreamId); + await _outboundControlStream.SendGoAwayFrameAsync(firstInvalidStreamId).ConfigureAwait(false); } catch (QuicException abortException) when (abortException.QuicError == QuicError.ConnectionAborted && abortException.ApplicationErrorCode == H3_NO_ERROR) { @@ -283,7 +283,7 @@ public async Task ShutdownAsync(bool failCurrentRequest = false) return; } - await WaitForClientDisconnectAsync(); + await WaitForClientDisconnectAsync().ConfigureAwait(false); } // Wait for the client to close the connection, e.g. after we send a GOAWAY, or after the HttpClient is disposed. @@ -315,10 +315,10 @@ public async Task WaitForClientDisconnectAsync(bool refuseNewRequests = true) // The client's control stream should throw QuicConnectionAbortedException, indicating that it was // aborted because the connection was closed (and was not explicitly closed or aborted prior to the connection being closed) - QuicException ex = await Assert.ThrowsAsync(async () => await _inboundControlStream.ReadFrameAsync()); + QuicException ex = await Assert.ThrowsAsync(async () => await _inboundControlStream.ReadFrameAsync().ConfigureAwait(false)); Assert.Equal(QuicError.ConnectionAborted, ex.QuicError); - await CloseAsync(H3_NO_ERROR); + await CloseAsync(H3_NO_ERROR).ConfigureAwait(false); } public override async Task WaitForCancellationAsync(bool ignoreIncomingData = true) diff --git a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs index 63368b49c129f..f6fbdf1f8cc14 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackServer.cs @@ -6,7 +6,6 @@ using System.IO; using System.Net.Quic; using System.Net.Security; -using System.Net.Sockets; using System.Security.Cryptography.X509Certificates; using System.Threading.Tasks; @@ -71,13 +70,13 @@ private async Task EstablishHttp3ConnectionAsync(params QuicConnection con = await _listener.AcceptConnectionAsync().ConfigureAwait(false); Http3LoopbackConnection connection = new Http3LoopbackConnection(con); - await connection.EstablishControlStreamAsync(settingsEntries); + await connection.EstablishControlStreamAsync(settingsEntries).ConfigureAwait(false); return connection; } public override async Task EstablishGenericConnectionAsync() { - return await EstablishHttp3ConnectionAsync(); + return await EstablishHttp3ConnectionAsync().ConfigureAwait(false); } public Task EstablishConnectionAsync(params SettingsEntry[] settingsEntries) @@ -89,12 +88,12 @@ public override async Task AcceptConnectionAsync(Func HandleRequestAsync(HttpStatusCode statusCode = HttpStatusCode.OK, IList headers = null, string content = "") { - await using Http3LoopbackConnection con = (Http3LoopbackConnection)await EstablishGenericConnectionAsync().ConfigureAwait(false); + await using Http3LoopbackConnection con = await EstablishHttp3ConnectionAsync().ConfigureAwait(false); return await con.HandleRequestAsync(statusCode, headers, content).ConfigureAwait(false); } } @@ -113,7 +112,7 @@ public override GenericLoopbackServer CreateServer(GenericLoopbackOptions option public override async Task CreateServerAsync(Func funcAsync, int millisecondsTimeout = LoopbackServerTimeoutMilliseconds, GenericLoopbackOptions options = null) { using GenericLoopbackServer server = CreateServer(options); - await funcAsync(server, server.Address).WaitAsync(TimeSpan.FromMilliseconds(millisecondsTimeout)); + await funcAsync(server, server.Address).WaitAsync(TimeSpan.FromMilliseconds(millisecondsTimeout)).ConfigureAwait(false); } public override Task CreateConnectionAsync(SocketWrapper socket, Stream stream, GenericLoopbackOptions options = null) diff --git a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackStream.cs b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackStream.cs index d8d0f9a7a7caf..778919eb4863d 100644 --- a/src/libraries/Common/tests/System/Net/Http/Http3LoopbackStream.cs +++ b/src/libraries/Common/tests/System/Net/Http/Http3LoopbackStream.cs @@ -124,7 +124,7 @@ private async Task SendPartialHeadersFrameAsync(HttpStatusCode? statusCode, IEnu { Memory payload = ConstructHeadersPayload(statusCode, headers); - await SendFrameHeaderAsync(HeadersFrame, payload.Length); + await SendFrameHeaderAsync(HeadersFrame, payload.Length).ConfigureAwait(false); // Slice off final byte so the payload is not complete payload = payload.Slice(0, payload.Length - 1); @@ -144,7 +144,7 @@ public async Task SendGoAwayFrameAsync(long firstInvalidStreamId) int bytesWritten = 0; bytesWritten += EncodeHttpInteger(firstInvalidStreamId, buffer); - await SendFrameAsync(GoAwayFrame, buffer.AsMemory(0, bytesWritten)); + await SendFrameAsync(GoAwayFrame, buffer.AsMemory(0, bytesWritten)).ConfigureAwait(false); } private async Task SendFrameHeaderAsync(long frameType, int payloadLength) @@ -367,11 +367,11 @@ async Task WaitForReadCancellation() { if (ignoreIncomingData) { - await DrainResponseData(); + await DrainResponseData().ConfigureAwait(false); } else { - int bytesRead = await _stream.ReadAsync(new byte[1]); + int bytesRead = await _stream.ReadAsync(new byte[1]).ConfigureAwait(false); if (bytesRead != 0) { throw new Exception($"Unexpected data received while waiting for client cancllation."); @@ -388,7 +388,7 @@ async Task WaitForWriteCancellation() { try { - await _stream.WritesClosed; + await _stream.WritesClosed.ConfigureAwait(false); } catch (QuicException ex) when (ex.QuicError == QuicError.StreamAborted && ex.ApplicationErrorCode == Http3LoopbackConnection.H3_REQUEST_CANCELLED) { @@ -396,7 +396,7 @@ async Task WaitForWriteCancellation() } } - await Task.WhenAll(WaitForReadCancellation(), WaitForWriteCancellation()); + await Task.WhenAll(WaitForReadCancellation(), WaitForWriteCancellation()).ConfigureAwait(false); if (!readCanceled && !writeCanceled) { diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.DefaultProxyCredentials.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.DefaultProxyCredentials.cs index 4ad8e2005a928..0924f2357ac4d 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.DefaultProxyCredentials.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.DefaultProxyCredentials.cs @@ -90,12 +90,12 @@ public async Task ProxySetViaEnvironmentVariable_DefaultProxyCredentialsUsed(boo const string ExpectedPassword = "rightpassword"; LoopbackServer.Options options = new LoopbackServer.Options { IsProxy = true, Username = ExpectedUsername, Password = ExpectedPassword }; - await LoopbackServer.CreateClientAndServerAsync(uri => Task.Run(() => + await LoopbackServer.CreateClientAndServerAsync(uri => Task.Run(async () => { var psi = new ProcessStartInfo(); psi.Environment.Add("http_proxy", $"http://{uri.Host}:{uri.Port}"); - RemoteExecutor.Invoke(async (useProxyString, useVersionString, uriString) => + await RemoteExecutor.Invoke(async (useProxyString, useVersionString, uriString) => { using (HttpClientHandler handler = CreateHttpClientHandler(useVersionString)) using (HttpClient client = CreateHttpClient(handler, useVersionString)) @@ -111,7 +111,7 @@ await LoopbackServer.CreateClientAndServerAsync(uri => Task.Run(() => }, useProxy.ToString(), UseVersion.ToString(), // If proxy is used , the url does not matter. We set it to be different to avoid confusion. useProxy ? Configuration.Http.RemoteEchoServer.ToString() : uri.ToString(), - new RemoteInvokeOptions { StartInfo = psi }).Dispose(); + new RemoteInvokeOptions { StartInfo = psi }).DisposeAsync(); }), server => server.AcceptConnectionAsync(async connection => { diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.ServerCertificates.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.ServerCertificates.cs index 236af85b26035..312eb90210815 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.ServerCertificates.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.ServerCertificates.cs @@ -382,7 +382,7 @@ public async Task PostAsync_Post_ChannelBinding_ConfiguredCorrectly() [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [PlatformSpecific(TestPlatforms.Linux)] - public void HttpClientUsesSslCertEnvironmentVariables() + public async Task HttpClientUsesSslCertEnvironmentVariables() { // We set SSL_CERT_DIR and SSL_CERT_FILE to empty locations. // The HttpClient should fail to validate the server certificate. @@ -395,7 +395,7 @@ public void HttpClientUsesSslCertEnvironmentVariables() File.WriteAllText(sslCertFile, ""); psi.Environment.Add("SSL_CERT_FILE", sslCertFile); - RemoteExecutor.Invoke(async (useVersionString, allowAllCertificatesString) => + await RemoteExecutor.Invoke(async (useVersionString, allowAllCertificatesString) => { const string Url = "https://www.microsoft.com"; var version = Version.Parse(useVersionString); @@ -405,7 +405,7 @@ public void HttpClientUsesSslCertEnvironmentVariables() using HttpClient client = CreateHttpClient(handler, useVersionString); await Assert.ThrowsAsync(() => client.GetAsync(Url)); - }, UseVersion.ToString(), AllowAllCertificates.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose(); + }, UseVersion.ToString(), AllowAllCertificates.ToString(), new RemoteInvokeOptions { StartInfo = psi }).DisposeAsync(); } } } diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs index 17af80b5ab645..20d8b33ed248d 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Net.Http.Headers; -using System.Net.Sockets; #if !NETFRAMEWORK using System.Net.Quic; #endif diff --git a/src/libraries/Common/tests/System/Net/RemoteExecutorExtensions.cs b/src/libraries/Common/tests/System/Net/RemoteExecutorExtensions.cs new file mode 100644 index 0000000000000..48ecfed7939ac --- /dev/null +++ b/src/libraries/Common/tests/System/Net/RemoteExecutorExtensions.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Threading.Tasks; +using Microsoft.DotNet.RemoteExecutor; + +namespace Microsoft.DotNet.RemoteExecutor; + +internal static class RemoteExecutorExtensions +{ + public static async ValueTask DisposeAsync(this RemoteInvokeHandle handle) + { + await Task.Run(handle.Dispose); + } +} diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/FunctionalTests/System.Net.Http.WinHttpHandler.Functional.Tests.csproj b/src/libraries/System.Net.Http.WinHttpHandler/tests/FunctionalTests/System.Net.Http.WinHttpHandler.Functional.Tests.csproj index 607b3ea038910..25c0dcc9cfb7c 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/tests/FunctionalTests/System.Net.Http.WinHttpHandler.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/FunctionalTests/System.Net.Http.WinHttpHandler.Functional.Tests.csproj @@ -32,6 +32,8 @@ Link="Common\System\Net\EventSourceTestLogging.cs" /> + + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { HttpRequestMessage requestLogged = null; HttpResponseMessage responseLogged = null; @@ -109,13 +109,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.False(exceptionLogged, "Exception was logged for successful request"); Assert.False(activityLogged, "HttpOutReq was logged while HttpOutReq logging was disabled"); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticSourceNoLogging() + public async Task SendAsync_ExpectedDiagnosticSourceNoLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { bool requestLogged = false; bool responseLogged = false; @@ -160,20 +160,20 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.False(responseLogged, "Response was logged while logging disabled."); Assert.False(activityStopLogged, "HttpRequestOut.Stop was logged while logging disabled."); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(false)] [InlineData(true)] - public void SendAsync_HttpTracingEnabled_Succeeds(bool useSsl) + public async Task SendAsync_HttpTracingEnabled_Succeeds(bool useSsl) { if (useSsl && UseVersion == HttpVersion.Version20 && !PlatformDetection.SupportsAlpn) { return; } - RemoteExecutor.Invoke(async (useVersion, useSsl, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, useSsl, testAsync) => { using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.Http", EventLevel.Verbose)) { @@ -194,13 +194,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( ev => ev.EventId == 0); // make sure there are no event source error messages Assert.InRange(events.Count, 1, int.MaxValue); } - }, UseVersion.ToString(), useSsl.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), useSsl.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticExceptionLogging() + public async Task SendAsync_ExpectedDiagnosticExceptionLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { Exception exceptionLogged = null; @@ -232,13 +232,13 @@ public void SendAsync_ExpectedDiagnosticExceptionLogging() Assert.Same(ex, exceptionLogged); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticCancelledLogging() + public async Task SendAsync_ExpectedDiagnosticCancelledLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { TaskCompletionSource responseLoggedTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); TaskCompletionSource activityStopTcs = new(TaskCreationOptions.RunContinuationsAsynchronously); @@ -284,15 +284,15 @@ await server.AcceptConnectionAsync(async connection => }); }); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(ActivityIdFormat.Hierarchical)] [InlineData(ActivityIdFormat.W3C)] - public void SendAsync_ExpectedDiagnosticSourceActivityLogging(ActivityIdFormat idFormat) + public async Task SendAsync_ExpectedDiagnosticSourceActivityLogging(ActivityIdFormat idFormat) { - RemoteExecutor.Invoke(async (useVersion, testAsync, idFormatString) => + await RemoteExecutor.Invoke(async (useVersion, testAsync, idFormatString) => { ActivityIdFormat idFormat = Enum.Parse(idFormatString); @@ -376,13 +376,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.False(exceptionLogged, "Exception was logged for successful request"); Assert.False(responseLogged, "Response was logged when Activity logging was enabled."); } - }, UseVersion.ToString(), TestAsync.ToString(), idFormat.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString(), idFormat.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticSourceActivityLogging_InvalidBaggage() + public async Task SendAsync_ExpectedDiagnosticSourceActivityLogging_InvalidBaggage() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { bool exceptionLogged = false; @@ -432,13 +432,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.False(exceptionLogged, "Exception was logged for successful request"); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticSourceActivityLoggingDoesNotOverwriteHeader() + public async Task SendAsync_ExpectedDiagnosticSourceActivityLoggingDoesNotOverwriteHeader() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { bool activityStartLogged = false; @@ -486,13 +486,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.True(activityStartLogged, "HttpRequestOut.Start was not logged."); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticSourceActivityLoggingDoesNotOverwriteW3CTraceParentHeader() + public async Task SendAsync_ExpectedDiagnosticSourceActivityLoggingDoesNotOverwriteW3CTraceParentHeader() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { bool activityStartLogged = false; @@ -544,13 +544,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.True(activityStartLogged, "HttpRequestOut.Start was not logged."); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticSourceUrlFilteredActivityLogging() + public async Task SendAsync_ExpectedDiagnosticSourceUrlFilteredActivityLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { bool activityStartLogged = false; bool activityStopLogged = false; @@ -588,13 +588,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.False(activityStartLogged, "HttpRequestOut.Start was logged while URL disabled."); Assert.False(activityStopLogged, "HttpRequestOut.Stop was logged while URL disabled."); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticExceptionActivityLogging() + public async Task SendAsync_ExpectedDiagnosticExceptionActivityLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { Exception exceptionLogged = null; @@ -627,13 +627,13 @@ public void SendAsync_ExpectedDiagnosticExceptionActivityLogging() Assert.Same(ex, exceptionLogged); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticSynchronousExceptionActivityLogging() + public async Task SendAsync_ExpectedDiagnosticSynchronousExceptionActivityLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { Exception exceptionLogged = null; @@ -704,13 +704,13 @@ public void SendAsync_ExpectedDiagnosticSynchronousExceptionActivityLogging() Assert.Same(exceptionLogged, exception); } } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticSourceNewAndDeprecatedEventsLogging() + public async Task SendAsync_ExpectedDiagnosticSourceNewAndDeprecatedEventsLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { bool requestLogged = false; bool activityStartLogged = false; @@ -755,13 +755,13 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.True(requestLogged, "Request was not logged."); Assert.True(activityStopLogged, "HttpRequestOut.Stop was not logged."); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendAsync_ExpectedDiagnosticExceptionOnlyActivityLogging() + public async Task SendAsync_ExpectedDiagnosticExceptionOnlyActivityLogging() { - RemoteExecutor.Invoke(async (useVersion, testAsync) => + await RemoteExecutor.Invoke(async (useVersion, testAsync) => { bool activityLogged = false; Exception exceptionLogged = null; @@ -793,7 +793,7 @@ public void SendAsync_ExpectedDiagnosticExceptionOnlyActivityLogging() Assert.Same(ex, exceptionLogged); Assert.False(activityLogged, "HttpOutReq was logged when logging was disabled"); } - }, UseVersion.ToString(), TestAsync.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString()).DisposeAsync(); } public static IEnumerable UseSocketsHttpHandler_WithIdFormat_MemberData() @@ -900,9 +900,9 @@ await GetFactoryForVersion(UseVersion).CreateServerAsync(async (redirectServer, [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(true)] [InlineData(false)] - public void SendAsync_SuppressedGlobalStaticPropagationNoListenerAppCtx(bool switchValue) + public async Task SendAsync_SuppressedGlobalStaticPropagationNoListenerAppCtx(bool switchValue) { - RemoteExecutor.Invoke(async (useVersion, testAsync, switchValue) => + await RemoteExecutor.Invoke(async (useVersion, testAsync, switchValue) => { AppContext.SetSwitch(EnableActivityPropagationAppCtxSettingName, bool.Parse(switchValue)); @@ -917,7 +917,7 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.Equal(bool.Parse(switchValue), request.Headers.Contains(headerName)); }, async server => await server.HandleRequestAsync()); - }, UseVersion.ToString(), TestAsync.ToString(), switchValue.ToString()).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString(), switchValue.ToString()).DisposeAsync(); } public static IEnumerable SocketsHttpHandlerPropagators_WithIdFormat_MemberData() @@ -987,11 +987,11 @@ public static IEnumerable SocketsHttpHandler_ActivityCreation_MemberDa [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(SocketsHttpHandler_ActivityCreation_MemberData))] - public void SendAsync_ActivityIsCreatedIfRequested(bool currentActivitySet, bool? diagnosticListenerActivityEnabled, bool? activitySourceCreatesActivity) + public async Task SendAsync_ActivityIsCreatedIfRequested(bool currentActivitySet, bool? diagnosticListenerActivityEnabled, bool? activitySourceCreatesActivity) { string parameters = $"{currentActivitySet},{diagnosticListenerActivityEnabled},{activitySourceCreatesActivity}"; - RemoteExecutor.Invoke(async (useVersion, testAsync, parametersString) => + await RemoteExecutor.Invoke(async (useVersion, testAsync, parametersString) => { bool?[] parameters = parametersString.Split(',').Select(p => p.Length == 0 ? (bool?)null : bool.Parse(p)).ToArray(); bool currentActivitySet = parameters[0].Value; @@ -1071,7 +1071,7 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync( Assert.Equal(activitySourceCreatesActivity.HasValue, madeASamplingDecision); Assert.Equal(diagnosticListenerActivityEnabled.HasValue, listenerCallbackWasCalled); - }, UseVersion.ToString(), TestAsync.ToString(), parameters).Dispose(); + }, UseVersion.ToString(), TestAsync.ToString(), parameters).DisposeAsync(); } private static T GetProperty(object obj, string propertyName) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs index dfbc00aea2799..bdf38ef6e7fb6 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs @@ -854,20 +854,20 @@ public void DefaultProxy_Get_ReturnsNotNull() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DefaultProxy_SetGet_Roundtrips() + public async Task DefaultProxy_SetGet_Roundtrips() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { IWebProxy proxy = new WebProxy("http://localhost:3128/"); HttpClient.DefaultProxy = proxy; Assert.True(Object.ReferenceEquals(proxy, HttpClient.DefaultProxy)); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DefaultProxy_Credentials_SetGet_Roundtrips() + public async Task DefaultProxy_Credentials_SetGet_Roundtrips() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { IWebProxy proxy = HttpClient.DefaultProxy; ICredentials nc = proxy.Credentials; @@ -879,7 +879,7 @@ public void DefaultProxy_Credentials_SetGet_Roundtrips() Assert.Same(nc, proxy.Credentials); return RemoteExecutor.SuccessExitCode; - }).Dispose(); + }).DisposeAsync(); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs index 74b7a1c5b0685..d7476a8bc6c6e 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs @@ -364,13 +364,13 @@ public Task RequestDuration_CustomTags_Recorded() [InlineData("System.Net.Http.HttpRequestOut.Start")] [InlineData("System.Net.Http.Request")] [InlineData("System.Net.Http.HttpRequestOut.Stop")] - public void RequestDuration_CustomTags_DiagnosticListener_Recorded(string eventName) + public async Task RequestDuration_CustomTags_DiagnosticListener_Recorded(string eventName) { - RemoteExecutor.Invoke(static async (testClassName, eventNameInner) => + await RemoteExecutor.Invoke(static async (testClassName, eventNameInner) => { using HttpMetricsTest test = (HttpMetricsTest)Activator.CreateInstance(Type.GetType(testClassName), (ITestOutputHelper)null); await test.RequestDuration_CustomTags_DiagnosticListener_Recorded_Core(eventNameInner); - }, GetType().FullName, eventName).Dispose(); + }, GetType().FullName, eventName).DisposeAsync(); } private async Task RequestDuration_CustomTags_DiagnosticListener_Recorded_Core(string eventName) @@ -1051,9 +1051,9 @@ public HttpMetricsTest_DefaultMeter(ITestOutputHelper output) : base(output) } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void ActiveRequests_Success_Recorded() + public async Task ActiveRequests_Success_Recorded() { - RemoteExecutor.Invoke(static async Task () => + await RemoteExecutor.Invoke(static async Task () => { using HttpMetricsTest_DefaultMeter test = new(null); await test.LoopbackServerFactory.CreateClientAndServerAsync(async uri => @@ -1072,7 +1072,7 @@ await test.LoopbackServerFactory.CreateClientAndServerAsync(async uri => { await server.AcceptConnectionSendResponseAndCloseAsync(); }); - }).Dispose(); + }).DisposeAsync(); } public static bool RemoteExecutorAndSocketsHttpHandlerSupported => RemoteExecutor.IsSupported && SocketsHttpHandler.IsSupported; @@ -1130,9 +1130,9 @@ await server.AcceptConnectionAsync(async connection => } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void RequestDuration_Success_Recorded() + public async Task RequestDuration_Success_Recorded() { - RemoteExecutor.Invoke(static async Task () => + await RemoteExecutor.Invoke(static async Task () => { using HttpMetricsTest_DefaultMeter test = new(null); await test.LoopbackServerFactory.CreateClientAndServerAsync(async uri => @@ -1148,7 +1148,7 @@ await test.LoopbackServerFactory.CreateClientAndServerAsync(async uri => { await server.AcceptConnectionSendResponseAndCloseAsync(HttpStatusCode.OK); }); - }).Dispose(); + }).DisposeAsync(); } } diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs index 76d7086c37c17..ae1669c18e68b 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Cancellation.cs @@ -305,7 +305,7 @@ public async Task CancelPendingRequest_DropsStalledConnectionAttempt() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void CancelPendingRequest_DropsStalledConnectionAttempt_CustomPendingConnectionTimeout() + public async Task CancelPendingRequest_DropsStalledConnectionAttempt_CustomPendingConnectionTimeout() { if (UseVersion == HttpVersion.Version30) { @@ -316,7 +316,7 @@ public void CancelPendingRequest_DropsStalledConnectionAttempt_CustomPendingConn RemoteInvokeOptions options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables["DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_PENDINGCONNECTIONTIMEOUTONREQUESTCOMPLETION"] = "42"; - RemoteExecutor.Invoke(CancelPendingRequest_DropsStalledConnectionAttempt_Impl, UseVersion.ToString(), options).Dispose(); + await RemoteExecutor.Invoke(CancelPendingRequest_DropsStalledConnectionAttempt_Impl, UseVersion.ToString(), options).DisposeAsync(); } private static async Task CancelPendingRequest_DropsStalledConnectionAttempt_Impl(string versionString) @@ -347,7 +347,7 @@ private static async Task CancelPendingRequest_DropsStalledConnectionAttempt_Imp [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(20_000)] [InlineData(Timeout.Infinite)] - public void PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled(int timeout) + public async Task PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled(int timeout) { if (UseVersion == HttpVersion.Version30) { @@ -355,7 +355,7 @@ public void PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled(i return; } - RemoteExecutor.Invoke(static async (versionString, timoutStr) => + await RemoteExecutor.Invoke(static async (versionString, timoutStr) => { // Setup "infinite" timeout of int.MaxValue milliseconds AppContext.SetData("System.Net.SocketsHttpHandler.PendingConnectionTimeoutOnRequestCompletion", int.Parse(timoutStr)); @@ -390,7 +390,7 @@ public void PendingConnectionTimeout_HighValue_PendingConnectionIsNotCancelled(i await Assert.ThrowsAnyAsync(() => client.GetAsync("https://dummy", requestCts.Token)).WaitAsync(TestHelper.PassingTestTimeout); await connectionTestTcs.Task.WaitAsync(TestHelper.PassingTestTimeout); - }, UseVersion.ToString(), timeout.ToString()).Dispose(); + }, UseVersion.ToString(), timeout.ToString()).DisposeAsync(); } private sealed class SetTcsContent : StreamContent diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Http2FlowControl.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Http2FlowControl.cs index f1dc09a9f7358..72382374cfc6e 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Http2FlowControl.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.Http2FlowControl.cs @@ -98,7 +98,7 @@ public async Task HighBandwidthDelayProduct_ClientStreamReceiveWindowWindowScale [OuterLoop("Runs long")] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DisableDynamicWindowScaling_HighBandwidthDelayProduct_WindowRemainsConstant() + public async Task DisableDynamicWindowScaling_HighBandwidthDelayProduct_WindowRemainsConstant() { static async Task RunTest() { @@ -113,12 +113,12 @@ static async Task RunTest() Assert.Equal(DefaultInitialWindowSize, maxCredit); } - RemoteExecutor.Invoke(RunTest).Dispose(); + await RemoteExecutor.Invoke(RunTest).DisposeAsync(); } [OuterLoop("Runs long")] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void MaxStreamWindowSize_WhenSet_WindowDoesNotScaleAboveMaximum() + public async Task MaxStreamWindowSize_WhenSet_WindowDoesNotScaleAboveMaximum() { const int MaxWindow = 654321; @@ -136,12 +136,12 @@ static async Task RunTest() RemoteInvokeOptions options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables["DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_FLOWCONTROL_MAXSTREAMWINDOWSIZE"] = MaxWindow.ToString(); - RemoteExecutor.Invoke(RunTest, options).Dispose(); + await RemoteExecutor.Invoke(RunTest, options).DisposeAsync(); } [OuterLoop("Runs long")] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void StreamWindowScaleThresholdMultiplier_HighValue_WindowScalesSlower() + public async Task StreamWindowScaleThresholdMultiplier_HighValue_WindowScalesSlower() { static async Task RunTest() { @@ -157,12 +157,12 @@ static async Task RunTest() RemoteInvokeOptions options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables["DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_FLOWCONTROL_STREAMWINDOWSCALETHRESHOLDMULTIPLIER"] = "10000"; // Extreme value - RemoteExecutor.Invoke(RunTest, options).Dispose(); + await RemoteExecutor.Invoke(RunTest, options).DisposeAsync(); } [OuterLoop("Runs long")] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void StreamWindowScaleThresholdMultiplier_LowValue_WindowScalesFaster() + public async Task StreamWindowScaleThresholdMultiplier_LowValue_WindowScalesFaster() { static async Task RunTest() { @@ -178,7 +178,7 @@ static async Task RunTest() RemoteInvokeOptions options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables["DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_FLOWCONTROL_STREAMWINDOWSCALETHRESHOLDMULTIPLIER"] = "0.00001"; // Extreme value - RemoteExecutor.Invoke(RunTest, options).Dispose(); + await RemoteExecutor.Invoke(RunTest, options).DisposeAsync(); } [OuterLoop("Runs long")] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs index f91fc2dda1dd3..6aec65ea7cf51 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs @@ -278,16 +278,16 @@ public SocketsHttpHandler_HttpClientHandler_MaxConnectionsPerServer_Test(ITestOu [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(true)] [InlineData(false)] - public void AppContextSetData_SetDefaultMaxConnectionsPerServer(bool asInt) + public async Task AppContextSetData_SetDefaultMaxConnectionsPerServer(bool asInt) { - RemoteExecutor.Invoke(static (asInt) => + await RemoteExecutor.Invoke(static (asInt) => { const int testValue = 123; object data = asInt == Boolean.TrueString ? testValue : testValue.ToString(); AppContext.SetData("System.Net.SocketsHttpHandler.MaxConnectionsPerServer", data); var handler = new HttpClientHandler(); Assert.Equal(testValue, handler.MaxConnectionsPerServer); - }, asInt.ToString()).Dispose(); + }, asInt.ToString()).DisposeAsync(); } [OuterLoop("Incurs a small delay")] @@ -1991,9 +1991,9 @@ await Http2LoopbackServerFactory.CreateServerAsync(async (server, url) => [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(false)] [InlineData(true)] - public void ConnectionsPooledThenDisposed_NoUnobservedTaskExceptions(bool secure) + public async Task ConnectionsPooledThenDisposed_NoUnobservedTaskExceptions(bool secure) { - RemoteExecutor.Invoke(async (secureString, useVersionString) => + await RemoteExecutor.Invoke(async (secureString, useVersionString) => { var releaseServer = new TaskCompletionSource(); await LoopbackServer.CreateClientAndServerAsync(async uri => @@ -2026,7 +2026,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => await releaseServer.Task; }), new LoopbackServer.Options { UseSsl = bool.Parse(secureString) }); - }, secure.ToString(), UseVersion.ToString()).Dispose(); + }, secure.ToString(), UseVersion.ToString()).DisposeAsync(); } [OuterLoop] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 0256d1d53a451..bdcdf4ada7c92 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -113,6 +113,8 @@ Link="Common\System\Net\SslProtocolSupport.cs" /> + TestMethods_MemberData() [OuterLoop] [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(TestMethods_MemberData))] - public void EventSource_SuccessfulRequest_LogsStartStop(string testMethod) + public async Task EventSource_SuccessfulRequest_LogsStartStop(string testMethod) { if (UseVersion.Major != 1 && !testMethod.EndsWith("Async")) { @@ -59,7 +59,7 @@ public void EventSource_SuccessfulRequest_LogsStartStop(string testMethod) return; } - RemoteExecutor.Invoke(static async (useVersionString, testMethod) => + await RemoteExecutor.Invoke(static async (useVersionString, testMethod) => { const int ResponseContentLength = 42; @@ -188,13 +188,13 @@ await server.AcceptConnectionAsync(async connection => count: 1); ValidateEventCounters(events, requestCount: 1, shouldHaveFailures: false, versionMajor: version.Major); - }, UseVersion.ToString(), testMethod).Dispose(); + }, UseVersion.ToString(), testMethod).DisposeAsync(); } [OuterLoop] [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(TestMethods_MemberData))] - public void EventSource_UnsuccessfulRequest_LogsStartFailedStop(string testMethod) + public async Task EventSource_UnsuccessfulRequest_LogsStartFailedStop(string testMethod) { if (UseVersion.Major != 1 && !testMethod.EndsWith("Async")) { @@ -202,7 +202,7 @@ public void EventSource_UnsuccessfulRequest_LogsStartFailedStop(string testMetho return; } - RemoteExecutor.Invoke(static async (useVersionString, testMethod) => + await RemoteExecutor.Invoke(static async (useVersionString, testMethod) => { Version version = Version.Parse(useVersionString); using var listener = new TestEventListener("System.Net.Http", EventLevel.Verbose, eventCounterInterval: 0.1d); @@ -293,7 +293,7 @@ await server.AcceptConnectionAsync(async connection => ValidateConnectionEstablishedClosed(events, version, expectedUri); ValidateEventCounters(events, requestCount: 1, shouldHaveFailures: true, versionMajor: version.Major); - }, UseVersion.ToString(), testMethod).Dispose(); + }, UseVersion.ToString(), testMethod).DisposeAsync(); } [OuterLoop] @@ -304,7 +304,7 @@ await server.AcceptConnectionAsync(async connection => [InlineData("SendChunkedAsync")] [InlineData("InvokerSend")] [InlineData("InvokerSendAsync")] - public void EventSource_SendingRequestContent_LogsRequestContentStartStop(string testMethod) + public async Task EventSource_SendingRequestContent_LogsRequestContentStartStop(string testMethod) { if (UseVersion.Major != 1 && !testMethod.EndsWith("Async")) { @@ -312,7 +312,7 @@ public void EventSource_SendingRequestContent_LogsRequestContentStartStop(string return; } - RemoteExecutor.Invoke(static async (useVersionString, testMethod) => + await RemoteExecutor.Invoke(static async (useVersionString, testMethod) => { const int RequestContentLength = 42; const int ResponseContentLength = 43; @@ -396,7 +396,7 @@ await server.AcceptConnectionAsync(async connection => count: 1); ValidateEventCounters(events, requestCount: 1, shouldHaveFailures: false, versionMajor: version.Major); - }, UseVersion.ToString(), testMethod).Dispose(); + }, UseVersion.ToString(), testMethod).DisposeAsync(); } private static void ValidateStartFailedStopEvents(ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)> events, Version version, bool shouldHaveFailures = false, int count = 1) @@ -665,9 +665,9 @@ private static void ValidateEventCounters(ConcurrentQueue<(EventWrittenEventArgs [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void EventSource_ConnectionPoolAtMaxConnections_LogsRequestLeftQueue() + public async Task EventSource_ConnectionPoolAtMaxConnections_LogsRequestLeftQueue() { - RemoteExecutor.Invoke(static async (useVersionString) => + await RemoteExecutor.Invoke(static async (useVersionString) => { Version version = Version.Parse(useVersionString); using var listener = new TestEventListener("System.Net.Http", EventLevel.Verbose, eventCounterInterval: 0.1d); @@ -774,14 +774,14 @@ await GetFactoryForVersion(version).CreateClientAndServerAsync( ValidateRequestResponseStartStopEvents(events, requestContentLength: null, responseContentLength: 0, count: 3); ValidateEventCounters(events, requestCount: 3, shouldHaveFailures: false, versionMajor: version.Major, requestLeftQueue: true); - }, UseVersion.ToString()).Dispose(); + }, UseVersion.ToString()).DisposeAsync(); } [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void EventSource_Redirect_LogsRedirect() + public async Task EventSource_Redirect_LogsRedirect() { - RemoteExecutor.Invoke(static async (string useVersionString) => + await RemoteExecutor.Invoke(static async (string useVersionString) => { Version version = Version.Parse(useVersionString); @@ -821,7 +821,7 @@ await GetFactoryForVersion(version).CreateServerAsync((originalServer, originalU Assert.Equal(1, redirectEvent.Payload.Count); Assert.Equal(expectedUri.ToString(), (string)redirectEvent.Payload[0]); Assert.Equal("redirectUri", redirectEvent.PayloadNames[0]); - }, UseVersion.ToString()).Dispose(); + }, UseVersion.ToString()).DisposeAsync(); } public static bool SupportsRemoteExecutorAndAlpn = RemoteExecutor.IsSupported && PlatformDetection.SupportsAlpn; @@ -903,9 +903,9 @@ public TelemetryTest_Http11(ITestOutputHelper output) : base(output) { } [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void EventSource_ParallelRequests_LogsNewConnectionIdForEachRequest() + public async Task EventSource_ParallelRequests_LogsNewConnectionIdForEachRequest() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { const int NumParallelRequests = 4; @@ -970,7 +970,7 @@ async Task HandleConnectionAsync(GenericLoopbackConnection connection) Assert.True(connectionIds.Remove(connectionId), $"RequestHeadersStart has logged an unexpected connectionId={connectionId}."); } Assert.Empty(connectionIds); - }).Dispose(); + }).DisposeAsync(); } } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs index 595c07a18ad81..6d9d50acde4d3 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Linq; using System.Net.Http.Headers; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; @@ -137,9 +138,9 @@ public void ToString_UseResponseDirectiveValues_AllSerializedCorrectly() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void ToString_NegativeValues_UsesMinusSignRegardlessOfCurrentCulture() + public async Task ToString_NegativeValues_UsesMinusSignRegardlessOfCurrentCulture() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { var cacheControl = new CacheControlHeaderValue() { @@ -155,7 +156,7 @@ public void ToString_NegativeValues_UsesMinusSignRegardlessOfCurrentCulture() CultureInfo.CurrentCulture = ci; Assert.Equal("max-age=-1, s-maxage=-4, max-stale=-2, min-fresh=-3", cacheControl.ToString()); - }).Dispose(); + }).DisposeAsync(); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/HttpEnvironmentProxyTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/HttpEnvironmentProxyTest.cs index 727e4f58d6908..a263f95bb27d8 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/HttpEnvironmentProxyTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/HttpEnvironmentProxyTest.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Net.Http; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; using Xunit.Abstractions; @@ -41,9 +42,9 @@ public HttpEnvironmentProxyTest(ITestOutputHelper output) } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void HttpProxy_EnvironmentProxy_Loaded() + public async Task HttpProxy_EnvironmentProxy_Loaded() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { IWebProxy p; @@ -123,7 +124,7 @@ public void HttpProxy_EnvironmentProxy_Loaded() Assert.True(u != null && u.Host == "1.1.1.3" && u.Port == 3003); u = p.GetProxy(fooWss); Assert.True(u != null && u.Host == "1.1.1.5" && u.Port == 3005); - }).Dispose(); + }).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] @@ -144,9 +145,9 @@ public void HttpProxy_EnvironmentProxy_Loaded() [InlineData("socks5://1.2.3.4:8888/foo", "1.2.3.4", "8888", null, null)] [InlineData("https://1.1.1.5:3005", "1.1.1.5", "3005", null, null)] [InlineData("https://1.1.1.5", "1.1.1.5", "443", null, null)] - public void HttpProxy_Uri_Parsing(string _input, string _host, string _port, string _user, string _password) + public async Task HttpProxy_Uri_Parsing(string _input, string _host, string _port, string _user, string _password) { - RemoteExecutor.Invoke((input, host, port, user, password) => + await RemoteExecutor.Invoke((input, host, port, user, password) => { // Remote exec does not allow to pass null at this moment. if (user == "null") @@ -178,13 +179,13 @@ public void HttpProxy_Uri_Parsing(string _input, string _host, string _port, str } return RemoteExecutor.SuccessExitCode; - }, _input, _host, _port, _user ?? "null", _password ?? "null").Dispose(); + }, _input, _host, _port, _user ?? "null", _password ?? "null").DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void HttpProxy_CredentialParsing_Basic() + public async Task HttpProxy_CredentialParsing_Basic() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { IWebProxy p; @@ -210,14 +211,14 @@ public void HttpProxy_CredentialParsing_Basic() // This should not match Proxy Uri Assert.Null(p.Credentials.GetCredential(fooHttp, "Basic")); Assert.Null(p.Credentials.GetCredential(null, null)); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void HttpProxy_CredentialParsing_DefaultCredentials() + public async Task HttpProxy_CredentialParsing_DefaultCredentials() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { IWebProxy p; @@ -231,13 +232,13 @@ public void HttpProxy_CredentialParsing_DefaultCredentials() Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.Equal(CredentialCache.DefaultCredentials, p.Credentials.GetCredential(p.GetProxy(fooHttp), "")); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void HttpProxy_Exceptions_Match() + public async Task HttpProxy_Exceptions_Match() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { IWebProxy p; @@ -251,7 +252,7 @@ public void HttpProxy_Exceptions_Match() Assert.True(p.IsBypassed(new Uri("http://test.com"))); Assert.False(p.IsBypassed(new Uri("http://1test.com"))); Assert.True(p.IsBypassed(new Uri("http://www.test.com"))); - }).Dispose(); + }).DisposeAsync(); } public static IEnumerable HttpProxyNoProxyEnvVarMemberData() @@ -264,14 +265,14 @@ public static IEnumerable HttpProxyNoProxyEnvVarMemberData() [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(HttpProxyNoProxyEnvVarMemberData))] - public void HttpProxy_TryCreate_CaseInsensitiveVariables(string proxyEnvVar, string noProxyEnvVar) + public async Task HttpProxy_TryCreate_CaseInsensitiveVariables(string proxyEnvVar, string noProxyEnvVar) { string proxy = "http://foo:PLACEHOLDER@1.1.1.1:3000"; var options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables.Add(proxyEnvVar, proxy); options.StartInfo.EnvironmentVariables.Add(noProxyEnvVar, ".test.com, foo.com"); - RemoteExecutor.Invoke((proxy) => + await RemoteExecutor.Invoke((proxy) => { var directUri = new Uri("http://test.com"); var thruProxyUri = new Uri("http://atest.com"); @@ -282,7 +283,7 @@ public void HttpProxy_TryCreate_CaseInsensitiveVariables(string proxyEnvVar, str Assert.True(p.IsBypassed(directUri)); Assert.False(p.IsBypassed(thruProxyUri)); Assert.Equal(new Uri(proxy), p.GetProxy(thruProxyUri)); - }, proxy, options).Dispose(); + }, proxy, options).DisposeAsync(); } public static IEnumerable HttpProxyCgiEnvVarMemberData() @@ -296,7 +297,7 @@ public static IEnumerable HttpProxyCgiEnvVarMemberData() [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(HttpProxyCgiEnvVarMemberData))] - public void HttpProxy_TryCreateAndPossibleCgi_HttpProxyUpperCaseDisabledInCgi( + public async Task HttpProxy_TryCreateAndPossibleCgi_HttpProxyUpperCaseDisabledInCgi( string proxyEnvVar, bool cgi, bool expectedProxyUse) { string proxy = "http://foo:PLACEHOLDER@1.1.1.1:3000"; @@ -308,7 +309,7 @@ public void HttpProxy_TryCreateAndPossibleCgi_HttpProxyUpperCaseDisabledInCgi( options.StartInfo.EnvironmentVariables.Add("GATEWAY_INTERFACE", "CGI/1.1"); } - RemoteExecutor.Invoke((proxy, expectedProxyUseString) => + await RemoteExecutor.Invoke((proxy, expectedProxyUseString) => { bool expectedProxyUse = bool.Parse(expectedProxyUseString); var destinationUri = new Uri("http://test.com"); @@ -324,7 +325,7 @@ public void HttpProxy_TryCreateAndPossibleCgi_HttpProxyUpperCaseDisabledInCgi( { Assert.False(created); } - }, proxy, expectedProxyUse.ToString(), options).Dispose(); + }, proxy, expectedProxyUse.ToString(), options).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/HttpWindowsProxyTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/HttpWindowsProxyTest.cs index 50357999b8762..df6648aab2730 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/HttpWindowsProxyTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/HttpWindowsProxyTest.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Net.Http; using System.Net.Http.WinHttpHandlerUnitTests; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; using Xunit.Abstractions; @@ -32,9 +33,9 @@ public HttpWindowsProxyTest(ITestOutputHelper output) [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(ProxyParsingData))] - public void HttpProxy_WindowsProxy_Manual_Loaded(string rawProxyString, string rawInsecureUri, string rawSecureUri) + public async Task HttpProxy_WindowsProxy_Manual_Loaded(string rawProxyString, string rawInsecureUri, string rawSecureUri) { - RemoteExecutor.Invoke((proxyString, insecureProxy, secureProxy) => + await RemoteExecutor.Invoke((proxyString, insecureProxy, secureProxy) => { FakeRegistry.Reset(); @@ -54,14 +55,14 @@ public void HttpProxy_WindowsProxy_Manual_Loaded(string rawProxyString, string r Assert.Equal(!string.IsNullOrEmpty(secureProxy) ? new Uri(secureProxy) : null, p.GetProxy(new Uri(fooHttps))); Assert.Equal(!string.IsNullOrEmpty(insecureProxy) ? new Uri(insecureProxy) : null, p.GetProxy(new Uri(fooWs))); Assert.Equal(!string.IsNullOrEmpty(secureProxy) ? new Uri(secureProxy) : null, p.GetProxy(new Uri(fooWss))); - }, rawProxyString, rawInsecureUri ?? string.Empty, rawSecureUri ?? string.Empty).Dispose(); + }, rawProxyString, rawInsecureUri ?? string.Empty, rawSecureUri ?? string.Empty).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(ProxyParsingData))] - public void HttpProxy_WindowsProxy_PAC_Loaded(string rawProxyString, string rawInsecureUri, string rawSecureUri) + public async Task HttpProxy_WindowsProxy_PAC_Loaded(string rawProxyString, string rawInsecureUri, string rawSecureUri) { - RemoteExecutor.Invoke((proxyString, insecureProxy, secureProxy) => + await RemoteExecutor.Invoke((proxyString, insecureProxy, secureProxy) => { TestControl.ResetAll(); @@ -87,7 +88,7 @@ public void HttpProxy_WindowsProxy_PAC_Loaded(string rawProxyString, string rawI Assert.Equal(!string.IsNullOrEmpty(secureProxy) ? new Uri(secureProxy) : null, p.GetProxy(new Uri(fooHttps))); Assert.Equal(!string.IsNullOrEmpty(insecureProxy) ? new Uri(insecureProxy) : null, p.GetProxy(new Uri(fooWs))); Assert.Equal(!string.IsNullOrEmpty(secureProxy) ? new Uri(secureProxy) : null, p.GetProxy(new Uri(fooWss))); - }, rawProxyString, rawInsecureUri ?? string.Empty, rawSecureUri ?? string.Empty).Dispose(); + }, rawProxyString, rawInsecureUri ?? string.Empty, rawSecureUri ?? string.Empty).DisposeAsync(); } public static TheoryData ProxyParsingData => @@ -117,9 +118,9 @@ public void HttpProxy_WindowsProxy_PAC_Loaded(string rawProxyString, string rawI [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData("localhost:1234", "http://localhost:1234/")] [InlineData("123.123.123.123", "http://123.123.123.123/")] - public void HttpProxy_WindowsProxy_Loaded(string rawProxyString, string expectedUri) + public async Task HttpProxy_WindowsProxy_Loaded(string rawProxyString, string expectedUri) { - RemoteExecutor.Invoke((proxyString, expectedString) => + await RemoteExecutor.Invoke((proxyString, expectedString) => { IWebProxy p; @@ -132,7 +133,7 @@ public void HttpProxy_WindowsProxy_Loaded(string rawProxyString, string expected Assert.NotNull(p); Assert.Equal(expectedString, p.GetProxy(new Uri(fooHttp)).ToString()); Assert.Equal(expectedString, p.GetProxy(new Uri(fooHttps)).ToString()); - }, rawProxyString, expectedUri).Dispose(); + }, rawProxyString, expectedUri).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] @@ -153,9 +154,9 @@ public void HttpProxy_WindowsProxy_Loaded(string rawProxyString, string expected [InlineData("http://[2607:f8B0:4005:80A::200E]/", true)] [InlineData("http://b\u00e9b\u00e9.eu/", true)] [InlineData("http://www.b\u00e9b\u00e9.eu/", true)] - public void HttpProxy_Local_Bypassed(string name, bool shouldBypass) + public async Task HttpProxy_Local_Bypassed(string name, bool shouldBypass) { - RemoteExecutor.Invoke((url, expected) => + await RemoteExecutor.Invoke((url, expected) => { bool expectedResult = Boolean.Parse(expected); IWebProxy p; @@ -169,7 +170,7 @@ public void HttpProxy_Local_Bypassed(string name, bool shouldBypass) Uri u = new Uri(url); Assert.Equal(expectedResult, p.GetProxy(u) == null); - }, name, shouldBypass.ToString()).Dispose(); + }, name, shouldBypass.ToString()).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] @@ -178,9 +179,9 @@ public void HttpProxy_Local_Bypassed(string name, bool shouldBypass) [InlineData(" ; ; ", 0)] [InlineData("http://127.0.0.1/", 1)] [InlineData("[::]", 1)] - public void HttpProxy_Local_Parsing(string bypass, int count) + public async Task HttpProxy_Local_Parsing(string bypass, int count) { - RemoteExecutor.Invoke((bypassValue, expected) => + await RemoteExecutor.Invoke((bypassValue, expected) => { int expectedCount = Convert.ToInt32(expected); IWebProxy p; @@ -203,7 +204,7 @@ public void HttpProxy_Local_Parsing(string bypass, int count) { Assert.Null(sp.BypassList); } - }, bypass, count.ToString()).Dispose(); + }, bypass, count.ToString()).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] @@ -212,9 +213,9 @@ public void HttpProxy_Local_Parsing(string bypass, int count) [InlineData("http://;")] [InlineData("http=;")] [InlineData(" ; ")] - public void HttpProxy_InvalidWindowsProxy_Null(string rawProxyString) + public async Task HttpProxy_InvalidWindowsProxy_Null(string rawProxyString) { - RemoteExecutor.Invoke((proxyString) => + await RemoteExecutor.Invoke((proxyString) => { IWebProxy p; @@ -231,14 +232,14 @@ public void HttpProxy_InvalidWindowsProxy_Null(string rawProxyString) Assert.Null(p.GetProxy(new Uri(fooHttps))); Assert.Null(p.GetProxy(new Uri(fooWs))); Assert.Null(p.GetProxy(new Uri(fooWss))); - }, rawProxyString).Dispose(); + }, rawProxyString).DisposeAsync(); } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(HttpProxy_Multi_Data))] - public void HttpProxy_Multi_Success(bool manualConfig, string proxyConfig, string url, string expected) + public async Task HttpProxy_Multi_Success(bool manualConfig, string proxyConfig, string url, string expected) { - RemoteExecutor.Invoke((manualConfigValue, proxyConfigValue, urlValue, expectedValue) => + await RemoteExecutor.Invoke((manualConfigValue, proxyConfigValue, urlValue, expectedValue) => { bool manual = bool.Parse(manualConfigValue); Uri requestUri = new Uri(urlValue); @@ -276,7 +277,7 @@ public void HttpProxy_Multi_Success(bool manualConfig, string proxyConfig, strin } Assert.False(multi.ReadNext(out _, out _)); - }, manualConfig.ToString(), proxyConfig, url, expected).Dispose(); + }, manualConfig.ToString(), proxyConfig, url, expected).DisposeAsync(); } public static IEnumerable HttpProxy_Multi_Data() @@ -294,11 +295,11 @@ public static IEnumerable HttpProxy_Multi_Data() [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(false)] [InlineData(true)] - public void HttpProxy_Multi_ConcurrentUse_Success(bool manualConfig) + public async Task HttpProxy_Multi_ConcurrentUse_Success(bool manualConfig) { const string MultiProxyConfig = "http://proxy-a.com http://proxy-b.com http://proxy-c.com"; - RemoteExecutor.Invoke(manualValue => + await RemoteExecutor.Invoke(manualValue => { bool manual = bool.Parse(manualValue); @@ -364,7 +365,7 @@ public void HttpProxy_Multi_ConcurrentUse_Success(bool manualConfig) Assert.True(multiC.ReadNext(out Uri proxyC, out _)); Assert.Equal(firstProxy, proxyC); Assert.False(multiC.ReadNext(out proxyC, out _)); - }, manualConfig.ToString()).Dispose(); + }, manualConfig.ToString()).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj index e8a6d2776a0dd..05f9963958ced 100755 --- a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj @@ -51,6 +51,8 @@ Link="Common\System\Net\Http\HPackEncoder.cs" /> + + await RemoteExecutor.Invoke(() => { IWebProxy proxy = SystemProxyInfo.ConstructSystemProxy(); Assert.NotNull(proxy); HttpEnvironmentProxy envProxy = proxy as HttpEnvironmentProxy; Assert.Null(envProxy); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void Ctor_ProxyEnvironmentVariableSet_IsHttpEnvironmentProxy() + public async Task Ctor_ProxyEnvironmentVariableSet_IsHttpEnvironmentProxy() { var options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables.Add("http_proxy", "http://proxy.contoso.com"); - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { IWebProxy proxy = SystemProxyInfo.ConstructSystemProxy(); HttpEnvironmentProxy envProxy = proxy as HttpEnvironmentProxy; Assert.NotNull(envProxy); - }, options).Dispose(); + }, options).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs b/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs index c4c9e801fd78c..188dd1711f52f 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/LoggingTest.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.Diagnostics.Tracing; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; @@ -25,9 +26,9 @@ public void EventSource_ExistsWithCorrectId() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void EventSource_EventsRaisedAsExpected() + public async Task EventSource_EventsRaisedAsExpected() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.Mail", EventLevel.Verbose)) { @@ -40,7 +41,7 @@ public void EventSource_EventsRaisedAsExpected() Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself Assert.InRange(events.Count, 1, int.MaxValue); } - }).Dispose(); + }).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj index 6ca3cb08be0d9..7336f9199077a 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj +++ b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj @@ -27,6 +27,8 @@ Link="Common\System\IO\TempFile.cs" /> + diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs index b968b6a0ab147..920a5af60cf00 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs @@ -30,11 +30,11 @@ public static void EventSource_ExistsWithCorrectId() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void GetHostEntry_InvalidHost_LogsError() + public async Task GetHostEntry_InvalidHost_LogsError() { try { - RemoteExecutor.Invoke(static () => + await RemoteExecutor.Invoke(static () => { using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error)) { @@ -65,7 +65,7 @@ public void GetHostEntry_InvalidHost_LogsError() Assert.NotNull(ev.Payload[2]); } } - }).Dispose(); + }).DisposeAsync(); } catch (Exception ex) when (ex.ToString().Contains(nameof(SkipTestException), StringComparison.Ordinal)) { @@ -74,11 +74,11 @@ public void GetHostEntry_InvalidHost_LogsError() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void GetHostEntryAsync_InvalidHost_LogsError() + public async Task GetHostEntryAsync_InvalidHost_LogsError() { try { - RemoteExecutor.Invoke(static async () => + await RemoteExecutor.Invoke(static async () => { using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error)) { @@ -110,7 +110,7 @@ await listener.RunWithCallbackAsync(ev => events.Enqueue(ev), async () => Assert.NotNull(ev.Payload[2]); } } - }).Dispose(); + }).DisposeAsync(); } catch (Exception ex) when (ex.ToString().Contains(nameof(SkipTestException), StringComparison.Ordinal)) { @@ -132,11 +132,11 @@ static async Task WaitForErrorEventAsync(ConcurrentQueue } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void GetHostEntry_ValidName_NoErrors() + public async Task GetHostEntry_ValidName_NoErrors() { try { - RemoteExecutor.Invoke(static () => + await RemoteExecutor.Invoke(static () => { using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Verbose)) { @@ -162,7 +162,7 @@ public void GetHostEntry_ValidName_NoErrors() // No errors or warning for successful query. Assert.True(events.Count(ev => (int)ev.Level > (int)EventLevel.Informational) == 0); } - }).Dispose(); + }).DisposeAsync(); } catch (Exception ex) when (ex.ToString().Contains(nameof(SkipTestException), StringComparison.Ordinal)) { diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs index a19d9edc476ab..e72a7f2940a13 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs @@ -17,9 +17,9 @@ public class MetricsTest private const string DnsLookupDuration = "dns.lookup.duration"; [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void ResolveValidHostName_MetricsRecorded() + public static async Task ResolveValidHostName_MetricsRecorded() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { const string ValidHostName = "localhost"; @@ -38,7 +38,7 @@ public static void ResolveValidHostName_MetricsRecorded() Assert.Equal(6, measurements.Length); Assert.All(measurements, m => Assert.True(m > double.Epsilon)); - }).Dispose(); + }).DisposeAsync(); } [Fact] diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj index 402868113d600..ff009e7b84326 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj @@ -24,6 +24,8 @@ Link="Common\System\Net\Configuration.cs" /> + + await RemoteExecutor.Invoke(async () => { const string ValidHostName = "microsoft.com"; @@ -51,14 +51,14 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn }); VerifyEvents(events, ValidHostName, 6); - }).Dispose(); + }).DisposeAsync(); } [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void EventSource_ResolveInvalidHostName_LogsStartFailureStop() + public static async Task EventSource_ResolveInvalidHostName_LogsStartFailureStop() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { const string InvalidHostName = "invalid...example.com"; @@ -79,14 +79,14 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn }); VerifyEvents(events, InvalidHostName, 6, shouldHaveFailures: true); - }).Dispose(); + }).DisposeAsync(); } [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void EventSource_GetHostEntryForIP_LogsStartStop() + public static async Task EventSource_GetHostEntryForIP_LogsStartStop() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { const string ValidIPAddress = "8.8.4.4"; @@ -110,7 +110,7 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn // Each GetHostEntry over an IP will yield 2 resolutions VerifyEvents(events, ValidIPAddress, 12, isHostEntryForIp: true); - }).Dispose(); + }).DisposeAsync(); } private static void VerifyEvents(ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)> events, string hostname, int expectedNumber, bool shouldHaveFailures = false, bool isHostEntryForIp = false) @@ -149,7 +149,7 @@ private static void VerifyEvents(ConcurrentQueue<(EventWrittenEventArgs Event, G } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void ResolutionsWaitingOnQueue_ResolutionStartCalledBeforeEnqueued() + public static async Task ResolutionsWaitingOnQueue_ResolutionStartCalledBeforeEnqueued() { // Some platforms (non-Windows) don't have proper support for GetAddrInfoAsync. // Instead we perform async-over-sync with a per-host queue. @@ -157,7 +157,7 @@ public static void ResolutionsWaitingOnQueue_ResolutionStartCalledBeforeEnqueued // We do this by blocking the first ResolutionStart event. // If the event was logged after waiting on the queue, the second request would never complete. - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { using var listener = new TestEventListener("System.Net.NameResolution", EventLevel.Informational); listener.AddActivityTracking(); @@ -221,7 +221,7 @@ static Task DoResolutionAsync() Assert.NotEqual(events[0].ActivityId, events[1].ActivityId); Assert.False(callbackWaitTimedOut); - }).Dispose(); + }).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs b/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs index 0b98a87e80cfa..f21cbce950a54 100644 --- a/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs +++ b/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs @@ -832,7 +832,7 @@ public void SendPingWithIPAddressAndTimeoutAndBufferAndPingOptions_ElevatedUnix( [InlineData(AddressFamily.InterNetworkV6, "ja_JP.UTF8", null, null)] [InlineData(AddressFamily.InterNetworkV6, "en_US.UTF8", "ja_JP.UTF8", null)] [InlineData(AddressFamily.InterNetworkV6, "en_US.UTF8", null, "ja_JP.UTF8")] - public void SendPing_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily, string envVar_LANG, string envVar_LC_MESSAGES, string envVar_LC_ALL) + public async Task SendPing_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily, string envVar_LANG, string envVar_LC_MESSAGES, string envVar_LC_ALL) { IPAddress localIpAddress = TestSettings.GetLocalIPAddress(addressFamily); if (localIpAddress == null) @@ -847,7 +847,7 @@ public void SendPing_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily, str remoteInvokeStartInfo.EnvironmentVariables["LC_MESSAGES"] = envVar_LC_MESSAGES; remoteInvokeStartInfo.EnvironmentVariables["LC_ALL"] = envVar_LC_ALL; - RemoteExecutor.Invoke(address => + await RemoteExecutor.Invoke(address => { SendBatchPing( (ping) => ping.Send(address, TestSettings.PingTimeout), @@ -855,7 +855,7 @@ public void SendPing_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily, str { PingResultValidator(pingReply, new IPAddress[] { IPAddress.Parse(address) }, null); }); - }, localIpAddress.ToString(), new RemoteInvokeOptions { StartInfo = remoteInvokeStartInfo }).Dispose(); + }, localIpAddress.ToString(), new RemoteInvokeOptions { StartInfo = remoteInvokeStartInfo }).DisposeAsync(); } [PlatformSpecific(TestPlatforms.AnyUnix)] @@ -866,7 +866,7 @@ public void SendPing_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily, str [InlineData(AddressFamily.InterNetworkV6, "ja_JP.UTF8", null, null)] [InlineData(AddressFamily.InterNetworkV6, "en_US.UTF8", "ja_JP.UTF8", null)] [InlineData(AddressFamily.InterNetworkV6, "en_US.UTF8", null, "ja_JP.UTF8")] - public void SendPingAsync_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily, string envVar_LANG, string envVar_LC_MESSAGES, string envVar_LC_ALL) + public async Task SendPingAsync_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily, string envVar_LANG, string envVar_LC_MESSAGES, string envVar_LC_ALL) { IPAddress localIpAddress = TestSettings.GetLocalIPAddress(addressFamily); @@ -879,7 +879,7 @@ public void SendPingAsync_LocaleEnvVarsMustBeIgnored(AddressFamily addressFamily } }; - RemoteExecutor.Invoke(async address => + await RemoteExecutor.Invoke(async address => { await SendBatchPingAsync( (ping) => ping.SendPingAsync(address), @@ -887,7 +887,7 @@ await SendBatchPingAsync( { PingResultValidator(pingReply, new IPAddress[] { IPAddress.Parse(address) }, null); }); - }, localIpAddress.ToString(), new RemoteInvokeOptions { StartInfo = remoteInvokeStartInfo }).Dispose(); + }, localIpAddress.ToString(), new RemoteInvokeOptions { StartInfo = remoteInvokeStartInfo }).DisposeAsync(); } [ConditionalFact(nameof(UsesPingUtility))] diff --git a/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj b/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj index bdacb51543d8c..8ac93b90759cf 100644 --- a/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj +++ b/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj @@ -18,6 +18,8 @@ + + await RemoteExecutor.Invoke(() => { using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.Primitives", EventLevel.Verbose)) { @@ -40,7 +41,7 @@ public void EventSource_EventsRaisedAsExpected() Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself Assert.InRange(events.Count, 1, int.MaxValue); } - }).Dispose(); + }).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj b/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj index 86fc2553bd379..89ce40cdd2b1f 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/System.Net.Primitives.Functional.Tests.csproj @@ -25,7 +25,10 @@ - + + \ No newline at end of file diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicRemoteExecutorTests.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicRemoteExecutorTests.cs index d2a40a1f35af5..68e6a88403df8 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicRemoteExecutorTests.cs +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicRemoteExecutorTests.cs @@ -23,7 +23,7 @@ public MsQuicRemoteExecutorTests() [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(true)] [InlineData(false)] - public void SslKeyLogFile_IsCreatedAndFilled(bool enabledBySwitch) + public async Task SslKeyLogFile_IsCreatedAndFilled(bool enabledBySwitch) { if (PlatformDetection.IsDebugLibrary(typeof(QuicConnection).Assembly) && !enabledBySwitch) { @@ -36,7 +36,7 @@ public void SslKeyLogFile_IsCreatedAndFilled(bool enabledBySwitch) var tempFile = Path.GetTempFileName(); psi.Environment.Add("SSLKEYLOGFILE", tempFile); - RemoteExecutor.Invoke(async (enabledBySwitch) => + await RemoteExecutor.Invoke(async (enabledBySwitch) => { if (bool.Parse(enabledBySwitch)) { @@ -47,7 +47,7 @@ public void SslKeyLogFile_IsCreatedAndFilled(bool enabledBySwitch) await clientConnection.DisposeAsync(); await serverConnection.DisposeAsync(); } - , enabledBySwitch.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose(); + , enabledBySwitch.ToString(), new RemoteInvokeOptions { StartInfo = psi }).DisposeAsync(); if (enabledBySwitch) { diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj index 67faecde3b4c9..c237c7d942a95 100644 --- a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj +++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj @@ -25,6 +25,7 @@ + diff --git a/src/libraries/System.Net.Requests/tests/AuthenticationManagerTest.cs b/src/libraries/System.Net.Requests/tests/AuthenticationManagerTest.cs index f5e7654c255dc..51fe3c15be4bb 100644 --- a/src/libraries/System.Net.Requests/tests/AuthenticationManagerTest.cs +++ b/src/libraries/System.Net.Requests/tests/AuthenticationManagerTest.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; @@ -33,29 +34,29 @@ public void Unregister_Null_Throws() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void Register_Unregister_ModuleCountUnchanged() + public async Task Register_Unregister_ModuleCountUnchanged() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { int initialCount = GetModuleCount(); IAuthenticationModule module = new CustomModule(); AuthenticationManager.Register(module); AuthenticationManager.Unregister(module); Assert.Equal(initialCount, GetModuleCount()); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void Register_UnregisterByScheme_ModuleCountUnchanged() + public async Task Register_UnregisterByScheme_ModuleCountUnchanged() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { int initialCount = GetModuleCount(); IAuthenticationModule module = new CustomModule(); AuthenticationManager.Register(module); AuthenticationManager.Unregister("custom"); Assert.Equal(initialCount, GetModuleCount()); - }).Dispose(); + }).DisposeAsync(); } [Fact] @@ -68,11 +69,11 @@ public void RegisteredModules_DefaultCount_ExpectedValue() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void CredentialPolicy_Roundtrip() + public async Task CredentialPolicy_Roundtrip() { Assert.Null(AuthenticationManager.CredentialPolicy); - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { ICredentialPolicy cp = new DummyCredentialPolicy(); AuthenticationManager.CredentialPolicy = cp; @@ -80,17 +81,17 @@ public void CredentialPolicy_Roundtrip() AuthenticationManager.CredentialPolicy = null; Assert.Null(AuthenticationManager.CredentialPolicy); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void CustomTargetNameDictionary_ValidCollection() + public async Task CustomTargetNameDictionary_ValidCollection() { Assert.NotNull(AuthenticationManager.CustomTargetNameDictionary); Assert.Empty(AuthenticationManager.CustomTargetNameDictionary); Assert.Same(AuthenticationManager.CustomTargetNameDictionary, AuthenticationManager.CustomTargetNameDictionary); - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { string theKey = "http://www.contoso.com"; string theValue = "HTTP/www.contoso.com"; @@ -99,7 +100,7 @@ public void CustomTargetNameDictionary_ValidCollection() AuthenticationManager.CustomTargetNameDictionary.Clear(); Assert.Equal(0, AuthenticationManager.CustomTargetNameDictionary.Count); - }).Dispose(); + }).DisposeAsync(); } private static int GetModuleCount() diff --git a/src/libraries/System.Net.Requests/tests/GlobalProxySelectionTest.cs b/src/libraries/System.Net.Requests/tests/GlobalProxySelectionTest.cs index fa3bfeb7ce3c9..7dfcf91f52e42 100644 --- a/src/libraries/System.Net.Requests/tests/GlobalProxySelectionTest.cs +++ b/src/libraries/System.Net.Requests/tests/GlobalProxySelectionTest.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; @@ -37,9 +38,9 @@ public bool IsBypassed(Uri host) } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void Select_Success() + public async Task Select_Success() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { var myProxy = new MyWebProxy(); @@ -82,7 +83,7 @@ public void Select_Success() Assert.NotNull(GlobalProxySelection.Select); Assert.True(GlobalProxySelection.Select.IsBypassed(null)); // This is true for EmptyWebProxy, but not for most proxies #pragma warning restore 0618 - }).Dispose(); + }).DisposeAsync(); } [Fact] diff --git a/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs b/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs index c6d693cdf5004..99b96e89b53ee 100644 --- a/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs +++ b/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs @@ -785,9 +785,9 @@ public void Expect_Set100Continue_ThrowsArgumentException(Uri remoteServer) } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DefaultMaximumResponseHeadersLength_SetAndGetLength_ValuesMatch() + public async Task DefaultMaximumResponseHeadersLength_SetAndGetLength_ValuesMatch() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { int defaultMaximumResponseHeadersLength = HttpWebRequest.DefaultMaximumResponseHeadersLength; const int NewDefaultMaximumResponseHeadersLength = 255; @@ -801,13 +801,13 @@ public void DefaultMaximumResponseHeadersLength_SetAndGetLength_ValuesMatch() { HttpWebRequest.DefaultMaximumResponseHeadersLength = defaultMaximumResponseHeadersLength; } - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DefaultMaximumErrorResponseLength_SetAndGetLength_ValuesMatch() + public async Task DefaultMaximumErrorResponseLength_SetAndGetLength_ValuesMatch() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { int defaultMaximumErrorsResponseLength = HttpWebRequest.DefaultMaximumErrorResponseLength; const int NewDefaultMaximumErrorsResponseLength = 255; @@ -821,13 +821,13 @@ public void DefaultMaximumErrorResponseLength_SetAndGetLength_ValuesMatch() { HttpWebRequest.DefaultMaximumErrorResponseLength = defaultMaximumErrorsResponseLength; } - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DefaultCachePolicy_SetAndGetPolicyReload_ValuesMatch() + public async Task DefaultCachePolicy_SetAndGetPolicyReload_ValuesMatch() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { RequestCachePolicy requestCachePolicy = HttpWebRequest.DefaultCachePolicy; @@ -841,7 +841,7 @@ public void DefaultCachePolicy_SetAndGetPolicyReload_ValuesMatch() { HttpWebRequest.DefaultCachePolicy = requestCachePolicy; } - }).Dispose(); + }).DisposeAsync(); } [Theory, MemberData(nameof(EchoServers))] @@ -1608,7 +1608,7 @@ await LoopbackServer.CreateServerAsync(async (proxyServer, proxyUri) => proxyTask = proxyServer.AcceptConnectionPerformAuthenticationAndCloseAsync("Proxy-Authenticate: Basic realm=\"NetCore\"\r\n"); psi.Environment.Add("http_proxy", $"http://{proxyUri.Host}:{proxyUri.Port}"); - RemoteExecutor.Invoke(async (async, user, pw) => + await RemoteExecutor.Invoke(async (async, user, pw) => { WebRequest.DefaultWebProxy.Credentials = new NetworkCredential(user, pw); HttpWebRequest request = HttpWebRequest.CreateHttp(Configuration.Http.RemoteEchoServer); @@ -1617,7 +1617,7 @@ await LoopbackServer.CreateServerAsync(async (proxyServer, proxyUri) => { Assert.Equal(HttpStatusCode.OK, response.StatusCode); } - }, (this is HttpWebRequestTest_Async).ToString(), cred.UserName, cred.Password, new RemoteInvokeOptions { StartInfo = psi }).Dispose(); + }, (this is HttpWebRequestTest_Async).ToString(), cred.UserName, cred.Password, new RemoteInvokeOptions { StartInfo = psi }).DisposeAsync(); await proxyTask; }, options); @@ -1724,9 +1724,9 @@ public void MediaType_SetThenGet_ValuesMatch(Uri remoteServer) } [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported)), MemberData(nameof(MixedWebRequestParameters))] - public void GetResponseAsync_ParametersAreNotCachable_CreateNewClient(HttpWebRequestParameters requestParameters, bool connectionReusedParameter) + public async Task GetResponseAsync_ParametersAreNotCachable_CreateNewClient(HttpWebRequestParameters requestParameters, bool connectionReusedParameter) { - RemoteExecutor.Invoke(async (async, serializedParameters, connectionReusedString) => + await RemoteExecutor.Invoke(async (async, serializedParameters, connectionReusedString) => { var parameters = JsonSerializer.Deserialize(serializedParameters); @@ -1769,13 +1769,13 @@ public void GetResponseAsync_ParametersAreNotCachable_CreateNewClient(HttpWebReq } } } - }, (this is HttpWebRequestTest_Async).ToString(), JsonSerializer.Serialize(requestParameters), connectionReusedParameter.ToString()).Dispose(); + }, (this is HttpWebRequestTest_Async).ToString(), JsonSerializer.Serialize(requestParameters), connectionReusedParameter.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void GetResponseAsync_ParametersAreCachableButDifferent_CreateNewClient() + public async Task GetResponseAsync_ParametersAreCachableButDifferent_CreateNewClient() { - RemoteExecutor.Invoke(async (async) => + await RemoteExecutor.Invoke(async (async) => { using (var listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { @@ -1829,7 +1829,7 @@ public void GetResponseAsync_ParametersAreCachableButDifferent_CreateNewClient() } } } - }, (this is HttpWebRequestTest_Async).ToString()).Dispose(); + }, (this is HttpWebRequestTest_Async).ToString()).DisposeAsync(); } [Fact] @@ -2000,10 +2000,10 @@ await server.AcceptConnectionAsync(async connection => [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(RequestCacheLevel.NoCacheNoStore, "Cache-Control: no-store, no-cache")] [InlineData(RequestCacheLevel.Reload, "Cache-Control: no-cache")] - public void SendHttpGetRequest_WithGlobalCachePolicy_AddCacheHeaders( + public async Task SendHttpGetRequest_WithGlobalCachePolicy_AddCacheHeaders( RequestCacheLevel requestCacheLevel, string expectedHeader) { - RemoteExecutor.Invoke(async (async, reqCacheLevel, eh) => + await RemoteExecutor.Invoke(async (async, reqCacheLevel, eh) => { await LoopbackServer.CreateServerAsync(async (server, uri) => { @@ -2023,7 +2023,7 @@ await server.AcceptConnectionAsync(async connection => Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }); - }, (this is HttpWebRequestTest_Async).ToString(), requestCacheLevel.ToString(), expectedHeader).Dispose(); + }, (this is HttpWebRequestTest_Async).ToString(), requestCacheLevel.ToString(), expectedHeader).DisposeAsync(); } [Theory] @@ -2040,9 +2040,9 @@ public async Task SendHttpGetRequest_WithCachePolicyCacheOnly_ThrowException( } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendHttpGetRequest_WithGlobalCachePolicyBypassCache_DoNotAddCacheHeaders() + public async Task SendHttpGetRequest_WithGlobalCachePolicyBypassCache_DoNotAddCacheHeaders() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { await LoopbackServer.CreateServerAsync(async (server, uri) => { @@ -2066,7 +2066,7 @@ await server.AcceptConnectionAsync(async connection => Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }); - }).Dispose(); + }).DisposeAsync(); } [Fact] @@ -2310,9 +2310,9 @@ await server.AcceptConnectionAsync( } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendHttpRequest_WhenDefaultMaximumErrorResponseLengthSet_Success() + public async Task SendHttpRequest_WhenDefaultMaximumErrorResponseLengthSet_Success() { - RemoteExecutor.Invoke(async (async) => + await RemoteExecutor.Invoke(async (async) => { TaskCompletionSource tcs = new TaskCompletionSource(); await LoopbackServer.CreateClientAndServerAsync( @@ -2342,7 +2342,7 @@ await server.AcceptConnectionAsync( await tcs.Task; }); }); - }, IsAsync.ToString()).Dispose(); + }, IsAsync.ToString()).DisposeAsync(); } [Fact] @@ -2358,9 +2358,9 @@ public void HttpWebRequest_SetProtocolVersion_Success() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendHttpRequest_BindIPEndPoint_Success() + public async Task SendHttpRequest_BindIPEndPoint_Success() { - RemoteExecutor.Invoke(async (async) => + await RemoteExecutor.Invoke(async (async) => { TaskCompletionSource tcs = new TaskCompletionSource(); await LoopbackServer.CreateClientAndServerAsync( @@ -2386,13 +2386,13 @@ await server.AcceptConnectionAsync( await tcs.Task; }); }); - }, IsAsync.ToString()).Dispose(); + }, IsAsync.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendHttpRequest_BindIPEndPoint_Throws() + public async Task SendHttpRequest_BindIPEndPoint_Throws() { - RemoteExecutor.Invoke(async (async) => + await RemoteExecutor.Invoke(async (async) => { Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp); socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); @@ -2422,7 +2422,7 @@ public void SendHttpRequest_BindIPEndPoint_Throws() socket.Dispose(); cts.Dispose(); } - }, IsAsync.ToString()).Dispose(); + }, IsAsync.ToString()).DisposeAsync(); } [Fact] diff --git a/src/libraries/System.Net.Requests/tests/ServicePointTests/ServicePointManagerTest.cs b/src/libraries/System.Net.Requests/tests/ServicePointTests/ServicePointManagerTest.cs index 33f7d1ac48ba7..04eeb67ddc1be 100644 --- a/src/libraries/System.Net.Requests/tests/ServicePointTests/ServicePointManagerTest.cs +++ b/src/libraries/System.Net.Requests/tests/ServicePointTests/ServicePointManagerTest.cs @@ -3,6 +3,7 @@ using System.Net.Security; using System.Runtime.CompilerServices; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; @@ -195,9 +196,9 @@ public static void UseNagleAlgorithm_Roundtrips() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void InvalidArguments_Throw() + public static async Task InvalidArguments_Throw() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { const int ssl2Client = 0x00000008; const int ssl2Server = 0x00000004; @@ -221,7 +222,7 @@ public static void InvalidArguments_Throw() AssertExtensions.Throws("value", () => sp.ReceiveBufferSize = -2); AssertExtensions.Throws("keepAliveTime", () => sp.SetTcpKeepAlive(true, -1, 1)); AssertExtensions.Throws("keepAliveInterval", () => sp.SetTcpKeepAlive(true, 1, -1)); - }).Dispose(); + }).DisposeAsync(); } [Fact] @@ -246,9 +247,9 @@ public static void SecurityProtocol_Ssl3_NotSupported() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void FindServicePoint_ReturnsCachedServicePoint() + public static async Task FindServicePoint_ReturnsCachedServicePoint() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { const string Localhost = "http://localhost"; string address1 = "http://" + Guid.NewGuid().ToString("N"); @@ -278,15 +279,15 @@ public static void FindServicePoint_ReturnsCachedServicePoint() Assert.NotSame( ServicePointManager.FindServicePoint(address1, new FixedWebProxy(address1)), ServicePointManager.FindServicePoint(address1, new FixedWebProxy(address2))); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [ActiveIssue("https://github.com/dotnet/runtime/issues/36217", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoInterpreter))] [ActiveIssue("https://github.com/dotnet/runtime/issues/64674", typeof(PlatformDetection), nameof(PlatformDetection.IsArmv6Process))] - public static void FindServicePoint_Collectible() + public static async Task FindServicePoint_Collectible() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { string address = "http://" + Guid.NewGuid().ToString("N"); @@ -298,13 +299,13 @@ public static void FindServicePoint_Collectible() GC.Collect(); Assert.Equal(initial, GetExpect100Continue(address)); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void FindServicePoint_ReturnedServicePointMatchesExpectedValues() + public static async Task FindServicePoint_ReturnedServicePointMatchesExpectedValues() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { string address = "http://" + Guid.NewGuid().ToString("N"); @@ -325,13 +326,13 @@ public static void FindServicePoint_ReturnedServicePointMatchesExpectedValues() Assert.Equal(-1, sp.ReceiveBufferSize); Assert.True(sp.SupportsPipelining, "SupportsPipelining"); Assert.False(sp.UseNagleAlgorithm, "UseNagleAlgorithm"); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void FindServicePoint_PropertiesRoundtrip() + public static async Task FindServicePoint_PropertiesRoundtrip() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { string address = "http://" + Guid.NewGuid().ToString("N"); @@ -360,13 +361,13 @@ public static void FindServicePoint_PropertiesRoundtrip() Assert.Equal(expectedMaxIdleTime, sp2.MaxIdleTime); Assert.Equal(expectedReceiveBufferSize, sp2.ReceiveBufferSize); Assert.Equal(expectedUseNagleAlgorithm, sp2.UseNagleAlgorithm); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void FindServicePoint_NewServicePointsInheritCurrentValues() + public static async Task FindServicePoint_NewServicePointsInheritCurrentValues() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { string address1 = "http://" + Guid.NewGuid().ToString("N"); string address2 = "http://" + Guid.NewGuid().ToString("N"); @@ -390,7 +391,7 @@ public static void FindServicePoint_NewServicePointsInheritCurrentValues() ServicePointManager.Expect100Continue = orig100Continue; ServicePointManager.UseNagleAlgorithm = origNagle; - }).Dispose(); + }).DisposeAsync(); } // Separated out to avoid the JIT in debug builds interfering with object lifetimes diff --git a/src/libraries/System.Net.Requests/tests/ServicePointTests/System.Net.ServicePoint.Tests.csproj b/src/libraries/System.Net.Requests/tests/ServicePointTests/System.Net.ServicePoint.Tests.csproj index ee7e7c37eaf88..77850da2afaef 100644 --- a/src/libraries/System.Net.Requests/tests/ServicePointTests/System.Net.ServicePoint.Tests.csproj +++ b/src/libraries/System.Net.Requests/tests/ServicePointTests/System.Net.ServicePoint.Tests.csproj @@ -9,5 +9,7 @@ + diff --git a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj index 828f168bd15f6..ea595a3dc0946 100644 --- a/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj +++ b/src/libraries/System.Net.Requests/tests/System.Net.Requests.Tests.csproj @@ -28,6 +28,8 @@ Link="Common\System\Net\Configuration.Security.cs" /> + + await RemoteExecutor.Invoke(() => { IWebProxy p = new WebProxy(); WebRequest.DefaultWebProxy = p; Assert.Same(p, WebRequest.DefaultWebProxy); - }).Dispose(); + }).DisposeAsync(); } [Fact] @@ -193,10 +193,10 @@ public void RegisterPrefix_DuplicateHttpWithFakeFactory_ExpectFalse() [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [InlineData(RequestCacheLevel.NoCacheNoStore, new string[] { "Pragma: no-cache", "Cache-Control: no-store, no-cache" })] [InlineData(RequestCacheLevel.Reload, new string[] { "Pragma: no-cache", "Cache-Control: no-cache" })] - public void SendGetRequest_WithGlobalCachePolicy_AddCacheHeaders( + public async Task SendGetRequest_WithGlobalCachePolicy_AddCacheHeaders( RequestCacheLevel requestCacheLevel, string[] expectedHeaders) { - RemoteExecutor.Invoke(async (reqCacheLevel, eh0, eh1) => + await RemoteExecutor.Invoke(async (reqCacheLevel, eh0, eh1) => { await LoopbackServer.CreateServerAsync(async (server, uri) => { @@ -216,13 +216,13 @@ await server.AcceptConnectionAsync(async connection => Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }); - }, requestCacheLevel.ToString(), expectedHeaders[0], expectedHeaders[1]).Dispose(); + }, requestCacheLevel.ToString(), expectedHeaders[0], expectedHeaders[1]).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void SendGetRequest_WithGlobalCachePolicyBypassCache_DoNotAddCacheHeaders() + public async Task SendGetRequest_WithGlobalCachePolicyBypassCache_DoNotAddCacheHeaders() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { await LoopbackServer.CreateServerAsync(async (server, uri) => { @@ -246,7 +246,7 @@ await server.AcceptConnectionAsync(async connection => Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }); - }).Dispose(); + }).DisposeAsync(); } private class FakeRequest : WebRequest diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/LoggingTest.cs index 87de0e09dc278..52a8282409aac 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/LoggingTest.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Diagnostics.Tracing; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Microsoft.DotNet.XUnitExtensions; using Xunit; @@ -25,9 +26,9 @@ public void EventSource_ExistsWithCorrectId() [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "X509 certificate store is not supported on iOS or tvOS.")] // Match SslStream_StreamToStream_Authentication_Success - public void EventSource_EventsRaisedAsExpected() + public async Task EventSource_EventsRaisedAsExpected() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { try { @@ -46,7 +47,7 @@ await listener.RunWithCallbackAsync(events.Enqueue, async () => { // Don't throw inside RemoteExecutor if SslStream_StreamToStream_Authentication_Success chose to skip the test } - }).Dispose(); + }).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs index 82cd3114eb477..87ec6605e37aa 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs @@ -25,7 +25,7 @@ public SslStreamRemoteExecutorTests() [PlatformSpecific(TestPlatforms.Linux)] // SSLKEYLOGFILE is only supported on Linux for SslStream [InlineData(true)] [InlineData(false)] - public void SslKeyLogFile_IsCreatedAndFilled(bool enabledBySwitch) + public async Task SslKeyLogFile_IsCreatedAndFilled(bool enabledBySwitch) { if (PlatformDetection.IsDebugLibrary(typeof(SslStream).Assembly) && !enabledBySwitch) { @@ -38,7 +38,7 @@ public void SslKeyLogFile_IsCreatedAndFilled(bool enabledBySwitch) var tempFile = Path.GetTempFileName(); psi.Environment.Add("SSLKEYLOGFILE", tempFile); - RemoteExecutor.Invoke(async (enabledBySwitch) => + await RemoteExecutor.Invoke(async (enabledBySwitch) => { if (bool.Parse(enabledBySwitch)) { @@ -64,7 +64,7 @@ await TestConfiguration.WhenAllOrAnyFailedWithTimeout( await TestHelper.PingPong(client, server); } - }, enabledBySwitch.ToString(), new RemoteInvokeOptions { StartInfo = psi }).Dispose(); + }, enabledBySwitch.ToString(), new RemoteInvokeOptions { StartInfo = psi }).DisposeAsync(); if (enabledBySwitch) { diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj index fe9c74708ad61..5fffd852c7506 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj @@ -85,6 +85,8 @@ Link="Common\System\Net\VerboseTestLogging.cs" /> + + await RemoteExecutor.Invoke(async () => { try { @@ -92,14 +92,14 @@ await listener.RunWithCallbackAsync(e => { // Don't throw inside RemoteExecutor if SslStream_StreamToStream_Authentication_Success chose to skip the test } - }).Dispose(); + }).DisposeAsync(); } [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void EventSource_UnsuccessfulHandshake_LogsStartFailureStop() + public static async Task EventSource_UnsuccessfulHandshake_LogsStartFailureStop() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { using var listener = new TestEventListener("System.Net.Security", EventLevel.Verbose, eventCounterInterval: 0.1d); listener.AddActivityTracking(); @@ -159,7 +159,7 @@ await listener.RunWithCallbackAsync(e => Assert.Equal(false, clientFailure.Payload[0]); VerifyEventCounters(events, shouldHaveFailures: true); - }).Dispose(); + }).DisposeAsync(); } private static SslProtocols ValidateHandshakeStopEventPayload(EventWrittenEventArgs stopEvent, bool failure = false) diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Accept.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Accept.cs index 57c4d32a9738a..819c3bc111027 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Accept.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Accept.cs @@ -392,9 +392,9 @@ public sealed class AcceptApm : Accept public AcceptApm(ITestOutputHelper output) : base(output) {} [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void AbortedByDispose_LeaksNoUnobservedExceptions() + public async Task AbortedByDispose_LeaksNoUnobservedExceptions() { - RemoteExecutor.Invoke(static async () => + await RemoteExecutor.Invoke(static async () => { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.BindToAnonymousPort(IPAddress.Loopback); @@ -431,7 +431,7 @@ await Task.Run(() => GC.WaitForPendingFinalizers(); Assert.False(unobservedThrown); - }).Dispose(); + }).DisposeAsync(); } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs index 4cc267e0113eb..52db82ab7c399 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/CreateSocketTests.cs @@ -131,14 +131,14 @@ public void Ctor_Raw_NotSupported_ExpectedError(AddressFamily addressFamily, Pro [InlineData(false, 1)] [InlineData(true, 2)] // Begin/EndAccept [InlineData(false, 2)] - public void CtorAndAccept_SocketNotKeptAliveViaInheritance(bool validateClientOuter, int acceptApiOuter) + public async Task CtorAndAccept_SocketNotKeptAliveViaInheritance(bool validateClientOuter, int acceptApiOuter) { // 300 ms should be long enough to connect if the socket is actually present & listening. const int ConnectionTimeoutMs = 300; // Run the test in another process so as to not have trouble with other tests // launching child processes that might impact inheritance. - RemoteExecutor.Invoke((validateClientString, acceptApiString) => + await RemoteExecutor.Invoke((validateClientString, acceptApiString) => { bool validateClient = bool.Parse(validateClientString); int acceptApi = int.Parse(acceptApiString); @@ -211,7 +211,7 @@ public void CtorAndAccept_SocketNotKeptAliveViaInheritance(bool validateClientOu } } } - }, validateClientOuter.ToString(), acceptApiOuter.ToString()).Dispose(); + }, validateClientOuter.ToString(), acceptApiOuter.ToString()).DisposeAsync(); } [Theory] diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/InlineCompletions.Unix.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/InlineCompletions.Unix.cs index 3b8f9bfc8927d..511b8b0dabe5e 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/InlineCompletions.Unix.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/InlineCompletions.Unix.cs @@ -15,13 +15,13 @@ public class InlineContinuations [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [PlatformSpecific(TestPlatforms.AnyUnix)] // Inline Socket mode is specific to Unix Socket implementation. - public void InlineSocketContinuations() + public async Task InlineSocketContinuations() { RemoteInvokeOptions options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables.Add("DOTNET_SYSTEM_NET_SOCKETS_INLINE_COMPLETIONS", "1"); options.TimeOut = (int)TimeSpan.FromMinutes(20).TotalMilliseconds; - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { // Connect/Accept tests await new AcceptEap(null).Accept_ConcurrentAcceptsBeforeConnects_Success(5); @@ -33,7 +33,7 @@ public void InlineSocketContinuations() await new SendReceive_Eap(null).SendRecv_Stream_TCP_MultipleConcurrentSends(IPAddress.Loopback, useMultipleBuffers: false); await new SendReceive_Eap(null).TcpReceiveSendGetsCanceledByDispose(receiveOrSend: true, ipv6Server: false, dualModeClient: false, owning: true); await new SendReceive_Eap(null).TcpReceiveSendGetsCanceledByDispose(receiveOrSend: false, ipv6Server: false, dualModeClient: false, owning: true); - }, options).Dispose(); + }, options).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/LoggingTest.cs index 134c80d9cf3e1..d23ee70a0b4a8 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/LoggingTest.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Diagnostics.Tracing; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; using Xunit.Abstractions; @@ -32,9 +33,9 @@ public static void EventSource_ExistsWithCorrectId() [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void EventSource_EventsRaisedAsExpected() + public async Task EventSource_EventsRaisedAsExpected() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.Sockets", EventLevel.Verbose)) { @@ -61,7 +62,7 @@ await listener.RunWithCallbackAsync(events.Enqueue, async () => Assert.DoesNotContain(events, ev => ev.EventId == 0); // errors from the EventSource itself Assert.InRange(events.Count, 1, int.MaxValue); } - }).Dispose(); + }).DisposeAsync(); } } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/OSSupport.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/OSSupport.cs index e103fde492b40..f7427e88da001 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/OSSupport.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/OSSupport.cs @@ -3,6 +3,7 @@ using System.Threading; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; @@ -27,11 +28,11 @@ public void SupportsIPv6_MatchesOSSupportsIPv6() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DisableIPv6_OSSupportsIPv6_False() + public async Task DisableIPv6_OSSupportsIPv6_False() { RemoteInvokeOptions options = new RemoteInvokeOptions(); options.StartInfo.EnvironmentVariables["DOTNET_SYSTEM_NET_DISABLEIPV6"] = "1"; - RemoteExecutor.Invoke(RunTest, options).Dispose(); + await RemoteExecutor.Invoke(RunTest, options).DisposeAsync(); static void RunTest() { @@ -40,9 +41,9 @@ static void RunTest() } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DisableIPv6_SocketConstructor_CreatesIPv4Socket() + public async Task DisableIPv6_SocketConstructor_CreatesIPv4Socket() { - RemoteExecutor.Invoke(RunTest).Dispose(); + await RemoteExecutor.Invoke(RunTest).DisposeAsync(); static void RunTest() { diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendReceive/SendReceive.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendReceive/SendReceive.cs index 0a65addc5c3f8..209f91b2ffba9 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendReceive/SendReceive.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendReceive/SendReceive.cs @@ -1187,9 +1187,9 @@ public SendReceive_Sync(ITestOutputHelper output) : base(output) { } [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void BlockingRead_DoesntRequireAnotherThreadPoolThread() + public async Task BlockingRead_DoesntRequireAnotherThreadPoolThread() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { // Set the max number of worker threads to a low value. ThreadPool.GetMaxThreads(out int workerThreads, out int completionPortThreads); @@ -1232,7 +1232,7 @@ select Task.Factory.StartNew(() => pair.Item1.Receive(new byte[1]), Cancellation pair.Item2.Dispose(); } } - }).Dispose(); + }).DisposeAsync(); } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketDuplicationTests.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketDuplicationTests.cs index b59c5ebd92a33..a9cb168de3ecc 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketDuplicationTests.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketDuplicationTests.cs @@ -161,7 +161,7 @@ public async Task DuplicateAndClose_TcpListener() [PlatformSpecific(TestPlatforms.Windows)] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void DuplicateSocket_IsNotInheritable() + public async Task DuplicateSocket_IsNotInheritable() { // 300 ms should be long enough to connect if the socket is actually present & listening. const int ConnectionTimeoutMs = 300; @@ -204,7 +204,7 @@ static void ChildProcessBody(string clientPipeHandle) // Run the test in another process so as to not have trouble with other tests // launching child processes that might impact inheritance. - RemoteExecutor.Invoke(RunTest).Dispose(); + await RemoteExecutor.Invoke(RunTest).DisposeAsync(); } [Fact] @@ -324,17 +324,20 @@ public async Task DuplicateAndClose_TcpServerHandler(AddressFamily addressFamily if (sameProcess) { Task handlerCode = Task.Run(() => HandlerServerCode(_ipcPipeName)); - RunCommonHostLogic(Environment.ProcessId); + await RunCommonHostLogic(Environment.ProcessId); await handlerCode; } else { - using RemoteInvokeHandle hServerProc = RemoteExecutor.Invoke(HandlerServerCode, _ipcPipeName); - RunCommonHostLogic(hServerProc.Process.Id); + RemoteInvokeHandle hServerProc = RemoteExecutor.Invoke(HandlerServerCode, _ipcPipeName); + await RunCommonHostLogic(hServerProc.Process.Id); + await hServerProc.DisposeAsync(); } - void RunCommonHostLogic(int processId) + async Task RunCommonHostLogic(int processId) { + await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding); + pipeServerStream.WaitForConnection(); // Duplicate the socket: diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/StartupTests.Windows.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/StartupTests.Windows.cs index 4666ea381ce8f..1f9c39daa0917 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/StartupTests.Windows.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/StartupTests.Windows.cs @@ -3,6 +3,7 @@ using System.IO.Pipes; using System.Runtime.InteropServices; +using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; using Xunit; @@ -16,82 +17,82 @@ public class StartupTests // RemoteExecutor is used so that the individual method is used as early in the process as possible. [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void OSSupportsIPv4() + public static async Task OSSupportsIPv4() { bool parentSupported = Socket.OSSupportsIPv4; - RemoteExecutor.Invoke(parentSupported => + await RemoteExecutor.Invoke(parentSupported => { Assert.Equal(bool.Parse(parentSupported), Socket.OSSupportsIPv4); - }, parentSupported.ToString()).Dispose(); + }, parentSupported.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void OSSupportsIPv6() + public static async Task OSSupportsIPv6() { bool parentSupported = Socket.OSSupportsIPv6; - RemoteExecutor.Invoke(parentSupported => + await RemoteExecutor.Invoke(parentSupported => { Assert.Equal(bool.Parse(parentSupported), Socket.OSSupportsIPv6); - }, parentSupported.ToString()).Dispose(); + }, parentSupported.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void OSSupportsUnixDomainSockets() + public static async Task OSSupportsUnixDomainSockets() { bool parentSupported = Socket.OSSupportsUnixDomainSockets; - RemoteExecutor.Invoke(parentSupported => + await RemoteExecutor.Invoke(parentSupported => { Assert.Equal(bool.Parse(parentSupported), Socket.OSSupportsUnixDomainSockets); - }, parentSupported.ToString()).Dispose(); + }, parentSupported.ToString()).DisposeAsync(); } #pragma warning disable CS0618 // SupportsIPv4 and SupportsIPv6 are obsolete [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void SupportsIPv4() + public static async Task SupportsIPv4() { bool parentSupported = Socket.SupportsIPv4; - RemoteExecutor.Invoke(parentSupported => + await RemoteExecutor.Invoke(parentSupported => { Assert.Equal(bool.Parse(parentSupported), Socket.SupportsIPv4); - }, parentSupported.ToString()).Dispose(); + }, parentSupported.ToString()).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void SupportsIPv6() + public static async Task SupportsIPv6() { bool parentSupported = Socket.SupportsIPv6; - RemoteExecutor.Invoke(parentSupported => + await RemoteExecutor.Invoke(parentSupported => { Assert.Equal(bool.Parse(parentSupported), Socket.SupportsIPv6); - }, parentSupported.ToString()).Dispose(); + }, parentSupported.ToString()).DisposeAsync(); } #pragma warning restore CS0618 [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void Ctor_SocketType_ProtocolType() + public static async Task Ctor_SocketType_ProtocolType() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { new Socket(SocketType.Stream, ProtocolType.Tcp).Dispose(); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void Ctor_AddressFamily_SocketType_ProtocolType() + public static async Task Ctor_AddressFamily_SocketType_ProtocolType() { - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp).Dispose(); - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public static void Ctor_SafeHandle() => RemoteExecutor.Invoke(() => + public static async Task Ctor_SafeHandle() => await RemoteExecutor.Invoke(() => { using var pipe = new AnonymousPipeServerStream(); using SafeHandle clientSafeHandle = pipe.ClientSafePipeHandle; SocketException se = Assert.Throws(() => new Socket(new SafeSocketHandle(clientSafeHandle.DangerousGetHandle(), ownsHandle: false))); Assert.Equal(SocketError.NotSocket, se.SocketErrorCode); - }).Dispose(); + }).DisposeAsync(); } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj b/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj index a1367f4a0b220..cc57803fa1c50 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/System.Net.Sockets.Tests.csproj @@ -86,6 +86,8 @@ Link="Common\System\Net\EventSourceTestLogging.cs" /> + + await RemoteExecutor.Invoke(async (connectMethod, acceptMethod) => { using var listener = new TestEventListener("System.Net.Sockets", EventLevel.Verbose, 0.1); listener.AddActivityTracking(); @@ -149,7 +149,7 @@ await listener.RunWithCallbackAsync(e => VerifyEvents(events, connect: true, expectedCount: 1); VerifyEvents(events, connect: false, expectedCount: 1); VerifyEventCounters(events, connectCount: 1, hasCurrentConnectCounter: true); - }, connectMethod, acceptMethod).Dispose(); + }, connectMethod, acceptMethod).DisposeAsync(); } [OuterLoop] @@ -162,7 +162,7 @@ public async Task EventSource_SocketConnectsRemote_LogsConnectStartStop(string c throw new SkipTestException("The remote server is not reachable"); } - RemoteExecutor.Invoke(async (connectMethod, useDnsEndPointString) => + await RemoteExecutor.Invoke(async (connectMethod, useDnsEndPointString) => { using var listener = new TestEventListener("System.Net.Sockets", EventLevel.Verbose, 0.1); listener.AddActivityTracking(); @@ -184,14 +184,14 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn VerifyEvents(events, connect: true, expectedCount: 1); VerifyEventCounters(events, connectCount: 1, connectOnly: true); - }, connectMethod, useDnsEndPoint.ToString()).Dispose(); + }, connectMethod, useDnsEndPoint.ToString()).DisposeAsync(); } [OuterLoop] [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD, "Same as Connect.ConnectGetsCanceledByDispose")] [MemberData(nameof(SocketMethods_WithBools_MemberData))] - public void EventSource_SocketConnectFailure_LogsConnectFailed(string connectMethod, bool useDnsEndPoint) + public async Task EventSource_SocketConnectFailure_LogsConnectFailed(string connectMethod, bool useDnsEndPoint) { // Skip test on Linux kernels that may have a regression that was fixed in 6.6. // See TcpReceiveSendGetsCanceledByDispose test for additional information. @@ -200,7 +200,7 @@ public void EventSource_SocketConnectFailure_LogsConnectFailed(string connectMet return; } - RemoteExecutor.Invoke(async (connectMethod, useDnsEndPointString) => + await RemoteExecutor.Invoke(async (connectMethod, useDnsEndPointString) => { EndPoint endPoint = await GetRemoteEndPointAsync(useDnsEndPointString, port: 12345); @@ -236,15 +236,15 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn int? expectedCount = bool.Parse(useDnsEndPointString) ? null : 1; VerifyEvents(events, connect: true, expectedCount, shouldHaveFailures: true); VerifyEventCounters(events, connectCount: 0); - }, connectMethod, useDnsEndPoint.ToString()).Dispose(); + }, connectMethod, useDnsEndPoint.ToString()).DisposeAsync(); } [OuterLoop] [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [MemberData(nameof(SocketMethods_MemberData))] - public void EventSource_SocketAcceptFailure_LogsAcceptFailed(string acceptMethod) + public async Task EventSource_SocketAcceptFailure_LogsAcceptFailed(string acceptMethod) { - RemoteExecutor.Invoke(async acceptMethod => + await RemoteExecutor.Invoke(async acceptMethod => { using var listener = new TestEventListener("System.Net.Sockets", EventLevel.Verbose, 0.1); listener.AddActivityTracking(); @@ -271,7 +271,7 @@ await Assert.ThrowsAnyAsync(async () => VerifyEvents(events, connect: false, expectedCount: 1, shouldHaveFailures: true); VerifyEventCounters(events, connectCount: 0); - }, acceptMethod).Dispose(); + }, acceptMethod).DisposeAsync(); } [OuterLoop] @@ -280,9 +280,9 @@ await Assert.ThrowsAnyAsync(async () => [InlineData("Task", false)] [InlineData("Eap", true)] [InlineData("Eap", false)] - public void EventSource_ConnectAsyncCanceled_LogsConnectFailed(string connectMethod, bool useDnsEndPoint) + public async Task EventSource_ConnectAsyncCanceled_LogsConnectFailed(string connectMethod, bool useDnsEndPoint) { - RemoteExecutor.Invoke(async (connectMethod, useDnsEndPointString) => + await RemoteExecutor.Invoke(async (connectMethod, useDnsEndPointString) => { EndPoint endPoint = await GetRemoteEndPointAsync(useDnsEndPointString, port: 12345); @@ -336,14 +336,14 @@ await Assert.ThrowsAnyAsync(async () => int? expectedCount = bool.Parse(useDnsEndPointString) ? null : 1; VerifyEvents(events, connect: true, expectedCount, shouldHaveFailures: true); VerifyEventCounters(events, connectCount: 0); - }, connectMethod, useDnsEndPoint.ToString()).Dispose(); + }, connectMethod, useDnsEndPoint.ToString()).DisposeAsync(); } [OuterLoop] [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - public void EventSource_EventsRaisedAsExpected() + public async Task EventSource_EventsRaisedAsExpected() { - RemoteExecutor.Invoke(async () => + await RemoteExecutor.Invoke(async () => { using (var listener = new TestEventListener("System.Net.Sockets", EventLevel.Verbose, 0.1)) { @@ -378,7 +378,7 @@ await listener.RunWithCallbackAsync(e => events.Enqueue((e, e.ActivityId)), asyn VerifyEvents(events, connect: true, expectedCount: 10); VerifyEventCounters(events, connectCount: 10, shouldHaveTransferredBytes: true, shouldHaveDatagrams: true); } - }).Dispose(); + }).DisposeAsync(); } private static async Task WaitForEventAsync(ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)> events, string name) diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs index a3e8501348375..58edc1ecffaa5 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs @@ -467,13 +467,13 @@ public void Socket_CreateUnixDomainSocket_Throws_OnWindows() [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [SkipOnPlatform(TestPlatforms.LinuxBionic, "SElinux blocks UNIX sockets in our CI environment")] - public void UnixDomainSocketEndPoint_RelativePathDeletesFile() + public async Task UnixDomainSocketEndPoint_RelativePathDeletesFile() { if (!Socket.OSSupportsUnixDomainSockets) { return; } - RemoteExecutor.Invoke(() => + await RemoteExecutor.Invoke(() => { using (Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified)) { @@ -501,7 +501,7 @@ public void UnixDomainSocketEndPoint_RelativePathDeletesFile() Directory.Delete(otherDir); } } - }).Dispose(); + }).DisposeAsync(); } [ConditionalFact(typeof(Socket), nameof(Socket.OSSupportsUnixDomainSockets))]