Skip to content

Commit 0e06c21

Browse files
authored
Convert Sync RemoteExecutors to Async on Http Tests (dotnet#115422)
* Convert Sync RemoteExecutors to Async * Fix build
1 parent 41e3612 commit 0e06c21

7 files changed

Lines changed: 46 additions & 43 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ await response.Content.ReadAsStringAsync(),
117117

118118
[OuterLoop("Uses external servers")]
119119
[ConditionalFact(nameof(IsSocketsHttpHandlerAndRemoteExecutorSupported))]
120-
public void Proxy_UseEnvironmentVariableToSetSystemProxy_RequestGoesThruProxy()
120+
public async Task Proxy_UseEnvironmentVariableToSetSystemProxy_RequestGoesThruProxy()
121121
{
122-
RemoteExecutor.Invoke(async (useVersionString) =>
122+
await RemoteExecutor.Invoke(async (useVersionString) =>
123123
{
124124
var options = new LoopbackProxyServer.Options { AddViaRequestHeader = true };
125125
using (LoopbackProxyServer proxyServer = LoopbackProxyServer.Create(options))
@@ -134,7 +134,7 @@ public void Proxy_UseEnvironmentVariableToSetSystemProxy_RequestGoesThruProxy()
134134
Assert.Contains(proxyServer.ViaHeader, body);
135135
}
136136
}
137-
}, UseVersion.ToString()).Dispose();
137+
}, UseVersion.ToString()).DisposeAsync();
138138
}
139139

140140
const string BasicAuth = "Basic";

src/libraries/System.Net.Http/tests/EnterpriseTests/HttpClientAuthenticationTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class HttpClientAuthenticationTest
2020
[InlineData(EnterpriseTestConfiguration.DigestAuthWebServer, true)]
2121
[InlineData(EnterpriseTestConfiguration.DigestAuthWebServer, false)]
2222
[InlineData(EnterpriseTestConfiguration.NtlmAuthWebServer, true)]
23-
public void HttpClient_ValidAuthentication_Success(string url, bool useDomain, bool useAltPort = false)
23+
public async Task HttpClient_ValidAuthentication_Success(string url, bool useDomain, bool useAltPort = false)
2424
{
25-
RemoteExecutor.Invoke((url, useAltPort, useDomain) =>
25+
await RemoteExecutor.Invoke((url, useAltPort, useDomain) =>
2626
{
2727
// This is safe as we have no parallel tests
2828
if (!string.IsNullOrEmpty(useAltPort))
@@ -35,7 +35,7 @@ public void HttpClient_ValidAuthentication_Success(string url, bool useDomain, b
3535

3636
using HttpResponseMessage response = client.GetAsync(url).GetAwaiter().GetResult();
3737
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
38-
}, url, useAltPort ? "true" : "" , useDomain ? "true" : "").Dispose();
38+
}, url, useAltPort ? "true" : "" , useDomain ? "true" : "").DisposeAsync();
3939
}
4040

4141
[Fact]

src/libraries/System.Net.Http/tests/EnterpriseTests/System.Net.Http.Enterprise.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
<Compile Include="$(CommonTestPath)System\Net\EnterpriseTests\EnterpriseTestConfiguration.cs"
1010
Link="Common\System\Net\EnterpriseTests\EnterpriseTestConfiguration.cs" />
11+
<Compile Include="$(CommonTestPath)System\Net\RemoteExecutorExtensions.cs"
12+
Link="Common\System\Net\RemoteExecutorExtensions.cs" />
1113
</ItemGroup>
1214
</Project>

src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,9 @@ public static IEnumerable<object[]> UseSocketsHttpHandler_WithIdFormat_MemberDat
12521252
[InlineData("fAlSe")]
12531253
[InlineData("helloworld")]
12541254
[InlineData("")]
1255-
public void SendAsync_SuppressedGlobalStaticPropagationEnvVar(string envVarValue)
1255+
public async Task SendAsync_SuppressedGlobalStaticPropagationEnvVar(string envVarValue)
12561256
{
1257-
RemoteExecutor.Invoke(async (useVersion, testAsync, envVarValue) =>
1257+
await RemoteExecutor.Invoke(async (useVersion, testAsync, envVarValue) =>
12581258
{
12591259
Environment.SetEnvironmentVariable(EnableActivityPropagationEnvironmentVariableSettingName, envVarValue);
12601260

@@ -1283,7 +1283,7 @@ await GetFactoryForVersion(useVersion).CreateClientAndServerAsync(
12831283

12841284
Assert.Equal(isInstrumentationEnabled, anyEventLogged);
12851285
}
1286-
}, UseVersion.ToString(), TestAsync.ToString(), envVarValue).Dispose();
1286+
}, UseVersion.ToString(), TestAsync.ToString(), envVarValue).DisposeAsync();
12871287
}
12881288

12891289
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]

src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,9 @@ await test.LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
14051405
public static bool RemoteExecutorAndSocketsHttpHandlerSupported => RemoteExecutor.IsSupported && SocketsHttpHandler.IsSupported;
14061406

14071407
[ConditionalFact(nameof(RemoteExecutorAndSocketsHttpHandlerSupported))]
1408-
public void AllSocketsHttpHandlerCounters_Success_Recorded()
1408+
public async Task AllSocketsHttpHandlerCounters_Success_Recorded()
14091409
{
1410-
RemoteExecutor.Invoke(static async Task () =>
1410+
await RemoteExecutor.Invoke(static async Task () =>
14111411
{
14121412
TaskCompletionSource clientWaitingTcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
14131413

@@ -1453,7 +1453,7 @@ await server.AcceptConnectionAsync(async connection =>
14531453
await connection.WaitForCloseAsync(CancellationToken.None);
14541454
});
14551455
});
1456-
}).Dispose();
1456+
}).DisposeAsync();
14571457
}
14581458

14591459
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]

src/libraries/System.Net.Http/tests/FunctionalTests/TelemetryTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,14 +996,14 @@ await GetFactoryForVersion(version).CreateServerAsync((originalServer, originalU
996996
[ConditionalTheory(nameof(SupportsRemoteExecutorAndAlpn))]
997997
[InlineData(false)]
998998
[InlineData(true)]
999-
public void EventSource_Proxy_LogsIPAddress(bool useSsl)
999+
public async Task EventSource_Proxy_LogsIPAddress(bool useSsl)
10001000
{
10011001
if (UseVersion.Major == 3)
10021002
{
10031003
return;
10041004
}
10051005

1006-
RemoteExecutor.Invoke(static async (string useVersionString, string useSslString) =>
1006+
await RemoteExecutor.Invoke(static async (string useVersionString, string useSslString) =>
10071007
{
10081008
using var listener = new TestEventListener("System.Net.Http", EventLevel.Verbose, eventCounterInterval: 0.1d);
10091009
listener.AddActivityTracking();
@@ -1038,7 +1038,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri =>
10381038
ip.Equals(IPAddress.Loopback) ||
10391039
ip.Equals(IPAddress.IPv6Loopback));
10401040
}
1041-
}, UseVersion.ToString(), useSsl.ToString()).Dispose();
1041+
}, UseVersion.ToString(), useSsl.ToString()).DisposeAsync();
10421042
}
10431043

10441044
protected static async Task WaitForEventCountersAsync(ConcurrentQueue<(EventWrittenEventArgs Event, Guid ActivityId)> events)

src/libraries/System.Net.Http/tests/UnitTests/RuntimeSettingParserTest.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Threading.Tasks;
45
using Microsoft.DotNet.RemoteExecutor;
56
using Xunit;
67

@@ -13,7 +14,7 @@ public class RuntimeSettingParserTest
1314
[ConditionalTheory(nameof(SupportsRemoteExecutor))]
1415
[InlineData(false)]
1516
[InlineData(true)]
16-
public void QueryRuntimeSettingSwitch_WhenNotSet_DefaultIsUsed(bool defaultValue)
17+
public async Task QueryRuntimeSettingSwitch_WhenNotSet_DefaultIsUsed(bool defaultValue)
1718
{
1819
static void RunTest(string defaultValueStr)
1920
{
@@ -22,11 +23,11 @@ static void RunTest(string defaultValueStr)
2223
Assert.Equal(expected, actual);
2324
}
2425

25-
RemoteExecutor.Invoke(RunTest, defaultValue.ToString()).Dispose();
26+
await RemoteExecutor.Invoke(RunTest, defaultValue.ToString()).DisposeAsync();
2627
}
2728

2829
[ConditionalFact(nameof(SupportsRemoteExecutor))]
29-
public void QueryRuntimeSettingSwitch_AppContextHasPriority()
30+
public async Task QueryRuntimeSettingSwitch_AppContextHasPriority()
3031
{
3132
static void RunTest()
3233
{
@@ -37,11 +38,11 @@ static void RunTest()
3738
RemoteInvokeOptions options = new RemoteInvokeOptions();
3839
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "true";
3940

40-
RemoteExecutor.Invoke(RunTest, options).Dispose();
41+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
4142
}
4243

4344
[ConditionalFact(nameof(SupportsRemoteExecutor))]
44-
public void QueryRuntimeSettingSwitch_EnvironmentVariable()
45+
public async Task QueryRuntimeSettingSwitch_EnvironmentVariable()
4546
{
4647
static void RunTest()
4748
{
@@ -51,11 +52,11 @@ static void RunTest()
5152
RemoteInvokeOptions options = new RemoteInvokeOptions();
5253
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "false";
5354

54-
RemoteExecutor.Invoke(RunTest, options).Dispose();
55+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
5556
}
5657

5758
[ConditionalFact(nameof(SupportsRemoteExecutor))]
58-
public void QueryRuntimeSettingSwitch_InvalidValue_FallbackToDefault()
59+
public async Task QueryRuntimeSettingSwitch_InvalidValue_FallbackToDefault()
5960
{
6061
static void RunTest()
6162
{
@@ -65,13 +66,13 @@ static void RunTest()
6566
RemoteInvokeOptions options = new RemoteInvokeOptions();
6667
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "cheese";
6768

68-
RemoteExecutor.Invoke(RunTest, options).Dispose();
69+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
6970
}
7071

7172
[ConditionalTheory(nameof(SupportsRemoteExecutor))]
7273
[InlineData(0)]
7374
[InlineData(42)]
74-
public void QueryRuntimeSettingInt32_WhenNotSet_DefaultIsUsed(int defaultValue)
75+
public async Task QueryRuntimeSettingInt32_WhenNotSet_DefaultIsUsed(int defaultValue)
7576
{
7677
static void RunTest(string defaultValueStr)
7778
{
@@ -80,11 +81,11 @@ static void RunTest(string defaultValueStr)
8081
Assert.Equal(expected, actual);
8182
}
8283

83-
RemoteExecutor.Invoke(RunTest, defaultValue.ToString()).Dispose();
84+
await RemoteExecutor.Invoke(RunTest, defaultValue.ToString()).DisposeAsync();
8485
}
8586

8687
[ConditionalFact(nameof(SupportsRemoteExecutor))]
87-
public void QueryRuntimeSettingInt32_AppContextHasPriority()
88+
public async Task QueryRuntimeSettingInt32_AppContextHasPriority()
8889
{
8990
static void RunTest()
9091
{
@@ -95,11 +96,11 @@ static void RunTest()
9596
RemoteInvokeOptions options = new RemoteInvokeOptions();
9697
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "3";
9798

98-
RemoteExecutor.Invoke(RunTest, options).Dispose();
99+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
99100
}
100101

101102
[ConditionalFact(nameof(SupportsRemoteExecutor))]
102-
public void QueryRuntimeSettingInt32_EnvironmentVariable()
103+
public async Task QueryRuntimeSettingInt32_EnvironmentVariable()
103104
{
104105
static void RunTest()
105106
{
@@ -109,12 +110,12 @@ static void RunTest()
109110
RemoteInvokeOptions options = new RemoteInvokeOptions();
110111
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "1";
111112

112-
RemoteExecutor.Invoke(RunTest, options).Dispose();
113+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
113114
}
114115

115116

116117
[ConditionalFact(nameof(SupportsRemoteExecutor))]
117-
public void QueryRuntimeSettingInt32_InvalidValue_FallbackToDefault()
118+
public async Task QueryRuntimeSettingInt32_InvalidValue_FallbackToDefault()
118119
{
119120
static void RunTest()
120121
{
@@ -124,22 +125,22 @@ static void RunTest()
124125
RemoteInvokeOptions options = new RemoteInvokeOptions();
125126
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "cheese";
126127

127-
RemoteExecutor.Invoke(RunTest, options).Dispose();
128+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
128129
}
129130

130131
[ConditionalFact(nameof(SupportsRemoteExecutor))]
131-
public void ParseInt32EnvironmentVariableValue_WhenNotSet_DefaultIsUsed()
132+
public async Task ParseInt32EnvironmentVariableValue_WhenNotSet_DefaultIsUsed()
132133
{
133134
static void RunTest()
134135
{
135136
int actual = RuntimeSettingParser.ParseInt32EnvironmentVariableValue("FOO_BAR", -42);
136137
Assert.Equal(-42, actual);
137138
}
138-
RemoteExecutor.Invoke(RunTest).Dispose();
139+
await RemoteExecutor.Invoke(RunTest).DisposeAsync();
139140
}
140141

141142
[ConditionalFact(nameof(SupportsRemoteExecutor))]
142-
public void ParseInt32EnvironmentVariableValue_ValidValue()
143+
public async Task ParseInt32EnvironmentVariableValue_ValidValue()
143144
{
144145
static void RunTest()
145146
{
@@ -150,11 +151,11 @@ static void RunTest()
150151
RemoteInvokeOptions options = new RemoteInvokeOptions();
151152
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "84";
152153

153-
RemoteExecutor.Invoke(RunTest, options).Dispose();
154+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
154155
}
155156

156157
[ConditionalFact(nameof(SupportsRemoteExecutor))]
157-
public void ParseInt32EnvironmentVariableValue_InvalidValue_FallbackToDefault()
158+
public async Task ParseInt32EnvironmentVariableValue_InvalidValue_FallbackToDefault()
158159
{
159160
static void RunTest()
160161
{
@@ -165,22 +166,22 @@ static void RunTest()
165166
RemoteInvokeOptions options = new RemoteInvokeOptions();
166167
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "-~4!";
167168

168-
RemoteExecutor.Invoke(RunTest, options).Dispose();
169+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
169170
}
170171

171172
[ConditionalFact(nameof(SupportsRemoteExecutor))]
172-
public void ParseDoubleEnvironmentVariableValue_WhenNotSet_DefaultIsUsed()
173+
public async Task ParseDoubleEnvironmentVariableValue_WhenNotSet_DefaultIsUsed()
173174
{
174175
static void RunTest()
175176
{
176177
double actual = RuntimeSettingParser.ParseDoubleEnvironmentVariableValue("FOO_BAR", -0.42);
177178
Assert.Equal(-0.42, actual);
178179
}
179-
RemoteExecutor.Invoke(RunTest).Dispose();
180+
await RemoteExecutor.Invoke(RunTest).DisposeAsync();
180181
}
181182

182183
[ConditionalFact(nameof(SupportsRemoteExecutor))]
183-
public void ParseDoubleEnvironmentVariableValue_ValidValue()
184+
public async Task ParseDoubleEnvironmentVariableValue_ValidValue()
184185
{
185186
static void RunTest()
186187
{
@@ -191,11 +192,11 @@ static void RunTest()
191192
RemoteInvokeOptions options = new RemoteInvokeOptions();
192193
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "0.84";
193194

194-
RemoteExecutor.Invoke(RunTest, options).Dispose();
195+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
195196
}
196197

197198
[ConditionalFact(nameof(SupportsRemoteExecutor))]
198-
public void ParseDoubleEnvironmentVariableValue_InvalidValue_FallbackToDefault()
199+
public async Task ParseDoubleEnvironmentVariableValue_InvalidValue_FallbackToDefault()
199200
{
200201
static void RunTest()
201202
{
@@ -206,7 +207,7 @@ static void RunTest()
206207
RemoteInvokeOptions options = new RemoteInvokeOptions();
207208
options.StartInfo.EnvironmentVariables["FOO_BAR"] = "-~4!";
208209

209-
RemoteExecutor.Invoke(RunTest, options).Dispose();
210+
await RemoteExecutor.Invoke(RunTest, options).DisposeAsync();
210211
}
211212
}
212213
}

0 commit comments

Comments
 (0)