Skip to content

Commit 7c52e28

Browse files
committed
Remove ConfigureAwait() calls from test code
Which requires ignoring the warning we enforce elsewhere. This resolves Warning xUnit1030, "Do not call ConfigureAwait in test method."
1 parent f8dc714 commit 7c52e28

12 files changed

+285
-279
lines changed

.editorconfig

-5
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,6 @@ dotnet_diagnostic.VSTHRD114.severity = error
116116
# VSTHRD200: Use "Async" suffix for awaitable methods
117117
dotnet_diagnostic.VSTHRD200.severity = silent
118118

119-
# xUnit2013: Do not use equality check to check for collection size
120-
dotnet_diagnostic.xUnit2013.severity = error
121-
# xUnit1004: Test methods should not be skipped
122-
dotnet_diagnostic.xUnit1004.severity = suggestion
123-
124119
# IDE0001: Simplify name
125120
dotnet_diagnostic.IDE0001.severity = error
126121
# IDE0002: Simplify member access

test/.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# not the top-most EditorConfig file
4+
root = false
5+
6+
[*.{cs}]
7+
# CA2007: Do not directly await a Task
8+
dotnet_diagnostic.CA2007.severity = none
9+
10+
# xUnit1004: Test methods should not be skipped
11+
dotnet_diagnostic.xUnit1004.severity = suggestion
12+
# xUnit1030: Do not call ConfigureAwait in test method
13+
dotnet_diagnostic.xUnit1030.severity = error
14+
# xUnit2013: Do not use equality check to check for collection size
15+
dotnet_diagnostic.xUnit2013.severity = error

test/PowerShellEditorServices.Test.E2E/DebugAdapterClientExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public static async Task LaunchScript(this DebugAdapterClient debugAdapterClient
2020
Script = script,
2121
Cwd = "",
2222
CreateTemporaryIntegratedConsole = false
23-
}).ConfigureAwait(true);
23+
});
2424

2525
if (launchResponse is null)
2626
{
2727
throw new Exception("Launch response was null.");
2828
}
2929

3030
// This will check to see if we received the Initialized event from the server.
31-
await started.Task.ConfigureAwait(true);
31+
await started.Task;
3232
}
3333
}
3434
}

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs

+32-32
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task InitializeAsync()
3939
{
4040
LoggerFactory factory = new();
4141
_psesProcess = new PsesStdioProcess(factory, true);
42-
await _psesProcess.Start().ConfigureAwait(true);
42+
await _psesProcess.Start();
4343

4444
TaskCompletionSource<bool> initialized = new();
4545

@@ -91,9 +91,9 @@ public async Task InitializeAsync()
9191
// This tells us that we are ready to send messages to PSES... but are not stuck waiting for
9292
// Initialized.
9393
#pragma warning disable CS4014
94-
PsesDebugAdapterClient.Initialize(CancellationToken.None).ConfigureAwait(true);
94+
PsesDebugAdapterClient.Initialize(CancellationToken.None);
9595
#pragma warning restore CS4014
96-
await initialized.Task.ConfigureAwait(true);
96+
await initialized.Task;
9797
}
9898

9999
public async Task DisposeAsync()
@@ -102,8 +102,8 @@ await PsesDebugAdapterClient.RequestDisconnect(new DisconnectArguments
102102
{
103103
Restart = false,
104104
TerminateDebuggee = true
105-
}).ConfigureAwait(true);
106-
await _psesProcess.Stop().ConfigureAwait(true);
105+
});
106+
await _psesProcess.Stop();
107107
}
108108

109109
public void Dispose()
@@ -164,10 +164,10 @@ private static async Task<string[]> GetLog()
164164
{
165165
for (int i = 0; !File.Exists(s_testOutputPath) && i < 60; i++)
166166
{
167-
await Task.Delay(1000).ConfigureAwait(true);
167+
await Task.Delay(1000);
168168
}
169169
// Sleep one more time after the file exists so whatever is writing can finish.
170-
await Task.Delay(1000).ConfigureAwait(true);
170+
await Task.Delay(1000);
171171
return File.ReadLines(s_testOutputPath).ToArray();
172172
}
173173

@@ -186,10 +186,10 @@ public void CanInitializeWithCorrectServerSettings()
186186
public async Task UsesDotSourceOperatorAndQuotesAsync()
187187
{
188188
string filePath = NewTestFile(GenerateScriptFromLoggingStatements("$($MyInvocation.Line)"));
189-
await PsesDebugAdapterClient.LaunchScript(filePath, Started).ConfigureAwait(true);
190-
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
189+
await PsesDebugAdapterClient.LaunchScript(filePath, Started);
190+
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments());
191191
Assert.NotNull(configDoneResponse);
192-
Assert.Collection(await GetLog().ConfigureAwait(true),
192+
Assert.Collection(await GetLog(),
193193
(i) => Assert.StartsWith(". '", i));
194194
}
195195

@@ -198,11 +198,11 @@ public async Task CanLaunchScriptWithNoBreakpointsAsync()
198198
{
199199
string filePath = NewTestFile(GenerateScriptFromLoggingStatements("works"));
200200

201-
await PsesDebugAdapterClient.LaunchScript(filePath, Started).ConfigureAwait(true);
201+
await PsesDebugAdapterClient.LaunchScript(filePath, Started);
202202

203-
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
203+
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments());
204204
Assert.NotNull(configDoneResponse);
205-
Assert.Collection(await GetLog().ConfigureAwait(true),
205+
Assert.Collection(await GetLog(),
206206
(i) => Assert.Equal("works", i));
207207
}
208208

@@ -218,32 +218,32 @@ public async Task CanSetBreakpointsAsync()
218218
"after breakpoint"
219219
));
220220

221-
await PsesDebugAdapterClient.LaunchScript(filePath, Started).ConfigureAwait(true);
221+
await PsesDebugAdapterClient.LaunchScript(filePath, Started);
222222

223223
// {"command":"setBreakpoints","arguments":{"source":{"name":"dfsdfg.ps1","path":"/Users/tyleonha/Code/PowerShell/Misc/foo/dfsdfg.ps1"},"lines":[2],"breakpoints":[{"line":2}],"sourceModified":false},"type":"request","seq":3}
224224
SetBreakpointsResponse setBreakpointsResponse = await PsesDebugAdapterClient.SetBreakpoints(new SetBreakpointsArguments
225225
{
226226
Source = new Source { Name = Path.GetFileName(filePath), Path = filePath },
227227
Breakpoints = new SourceBreakpoint[] { new SourceBreakpoint { Line = 2 } },
228228
SourceModified = false,
229-
}).ConfigureAwait(true);
229+
});
230230

231231
Breakpoint breakpoint = setBreakpointsResponse.Breakpoints.First();
232232
Assert.True(breakpoint.Verified);
233233
Assert.Equal(filePath, breakpoint.Source.Path, ignoreCase: s_isWindows);
234234
Assert.Equal(2, breakpoint.Line);
235235

236-
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
236+
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments());
237237
Assert.NotNull(configDoneResponse);
238-
Assert.Collection(await GetLog().ConfigureAwait(true),
238+
Assert.Collection(await GetLog(),
239239
(i) => Assert.Equal("before breakpoint", i));
240240
File.Delete(s_testOutputPath);
241241

242242
ContinueResponse continueResponse = await PsesDebugAdapterClient.RequestContinue(
243-
new ContinueArguments { ThreadId = 1 }).ConfigureAwait(true);
243+
new ContinueArguments { ThreadId = 1 });
244244

245245
Assert.NotNull(continueResponse);
246-
Assert.Collection(await GetLog().ConfigureAwait(true),
246+
Assert.Collection(await GetLog(),
247247
(i) => Assert.Equal("at breakpoint", i),
248248
(i) => Assert.Equal("after breakpoint", i));
249249
}
@@ -274,24 +274,24 @@ public async Task CanStepPastSystemWindowsForms()
274274
"Write-Host $form"
275275
}));
276276

277-
await PsesDebugAdapterClient.LaunchScript(filePath, Started).ConfigureAwait(true);
277+
await PsesDebugAdapterClient.LaunchScript(filePath, Started);
278278

279279
SetFunctionBreakpointsResponse setBreakpointsResponse = await PsesDebugAdapterClient.SetFunctionBreakpoints(
280280
new SetFunctionBreakpointsArguments
281281
{
282282
Breakpoints = new FunctionBreakpoint[]
283283
{ new FunctionBreakpoint { Name = "Write-Host", } }
284-
}).ConfigureAwait(true);
284+
});
285285

286286
Breakpoint breakpoint = setBreakpointsResponse.Breakpoints.First();
287287
Assert.True(breakpoint.Verified);
288288

289-
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
289+
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments());
290290
Assert.NotNull(configDoneResponse);
291-
await Task.Delay(5000).ConfigureAwait(true);
291+
await Task.Delay(5000);
292292

293293
VariablesResponse variablesResponse = await PsesDebugAdapterClient.RequestVariables(
294-
new VariablesArguments { VariablesReference = 1 }).ConfigureAwait(true);
294+
new VariablesArguments { VariablesReference = 1 });
295295

296296
Variable form = variablesResponse.Variables.FirstOrDefault(v => v.Name == "$form");
297297
Assert.NotNull(form);
@@ -312,15 +312,15 @@ public async Task CanLaunchScriptWithCommentedLastLineAsync()
312312
// PsesLaunchRequestArguments.Script, which is then assigned to
313313
// DebugStateService.ScriptToLaunch in that handler, and finally used by the
314314
// ConfigurationDoneHandler in LaunchScriptAsync.
315-
await PsesDebugAdapterClient.LaunchScript(script, Started).ConfigureAwait(true);
315+
await PsesDebugAdapterClient.LaunchScript(script, Started);
316316

317-
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
317+
ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments());
318318
Assert.NotNull(configDoneResponse);
319319
// We can check that the script was invoked as expected, which is to dot-source a script
320320
// block with the contents surrounded by newlines. While we can't check that the last
321321
// line was a curly brace by itself, we did check that the contents ended with a
322322
// comment, so if this output exists then the bug did not recur.
323-
Assert.Collection(await GetLog().ConfigureAwait(true),
323+
Assert.Collection(await GetLog(),
324324
(i) => Assert.Equal(". {", i),
325325
(i) => Assert.Equal("", i));
326326
}
@@ -342,9 +342,9 @@ public async Task CanRunPesterTestFile()
342342
using CancellationTokenSource cts = new(5000);
343343
while (!File.Exists(pesterLog) && !cts.Token.IsCancellationRequested)
344344
{
345-
await Task.Delay(1000).ConfigureAwait(true);
345+
await Task.Delay(1000);
346346
}
347-
await Task.Delay(15000).ConfigureAwait(true);
347+
await Task.Delay(15000);
348348
_output.WriteLine(File.ReadAllText(pesterLog));
349349
*/
350350

@@ -360,9 +360,9 @@ public async Task CanRunPesterTestFile()
360360
}
361361
}", isPester: true);
362362

363-
await PsesDebugAdapterClient.LaunchScript($"Invoke-Pester -Script '{pesterTest}'", Started).ConfigureAwait(true);
364-
await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true);
365-
Assert.Collection(await GetLog().ConfigureAwait(true), (i) => Assert.Equal("pester", i));
363+
await PsesDebugAdapterClient.LaunchScript($"Invoke-Pester -Script '{pesterTest}'", Started);
364+
await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments());
365+
Assert.Collection(await GetLog(), (i) => Assert.Equal("pester", i));
366366
}
367367
}
368368
}

test/PowerShellEditorServices.Test.E2E/LSPTestsFixures.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task InitializeAsync()
4545
{
4646
LoggerFactory factory = new();
4747
_psesProcess = new PsesStdioProcess(factory, IsDebugAdapterTests);
48-
await _psesProcess.Start().ConfigureAwait(false);
48+
await _psesProcess.Start();
4949

5050
DirectoryInfo testDir =
5151
Directory.CreateDirectory(Path.Combine(s_binDir, Path.GetRandomFileName()));
@@ -79,7 +79,7 @@ public async Task InitializeAsync()
7979
}
8080
});
8181

82-
await PsesLanguageClient.Initialize(CancellationToken.None).ConfigureAwait(false);
82+
await PsesLanguageClient.Initialize(CancellationToken.None);
8383

8484
// Make sure Script Analysis is enabled because we'll need it in the tests.
8585
// This also makes sure the configuration is set to default values.
@@ -97,8 +97,8 @@ public async Task InitializeAsync()
9797

9898
public async Task DisposeAsync()
9999
{
100-
await PsesLanguageClient.Shutdown().ConfigureAwait(false);
101-
await _psesProcess.Stop().ConfigureAwait(false);
100+
await PsesLanguageClient.Shutdown();
101+
await _psesProcess.Stop();
102102
PsesLanguageClient?.Dispose();
103103
}
104104
}

0 commit comments

Comments
 (0)