@@ -39,7 +39,7 @@ public async Task InitializeAsync()
39
39
{
40
40
LoggerFactory factory = new ( ) ;
41
41
_psesProcess = new PsesStdioProcess ( factory , true ) ;
42
- await _psesProcess . Start ( ) . ConfigureAwait ( false ) ;
42
+ await _psesProcess . Start ( ) . ConfigureAwait ( true ) ;
43
43
44
44
TaskCompletionSource < bool > initialized = new ( ) ;
45
45
@@ -90,26 +90,21 @@ public async Task InitializeAsync()
90
90
// that gets completed when we receive the response to Initialize
91
91
// This tells us that we are ready to send messages to PSES... but are not stuck waiting for
92
92
// Initialized.
93
- PsesDebugAdapterClient . Initialize ( CancellationToken . None ) . ConfigureAwait ( false ) ;
94
- await initialized . Task . ConfigureAwait ( false ) ;
93
+ #pragma warning disable CS4014
94
+ PsesDebugAdapterClient . Initialize ( CancellationToken . None ) . ConfigureAwait ( true ) ;
95
+ #pragma warning restore CS4014
96
+ await initialized . Task . ConfigureAwait ( true ) ;
95
97
}
96
98
97
99
public async Task DisposeAsync ( )
98
100
{
99
- try
101
+ await PsesDebugAdapterClient . RequestDisconnect ( new DisconnectArguments
100
102
{
101
- await PsesDebugAdapterClient . RequestDisconnect ( new DisconnectArguments
102
- {
103
- Restart = false ,
104
- TerminateDebuggee = true
105
- } ) . ConfigureAwait ( false ) ;
106
- await _psesProcess . Stop ( ) . ConfigureAwait ( false ) ;
107
- PsesDebugAdapterClient ? . Dispose ( ) ;
108
- }
109
- catch ( ObjectDisposedException )
110
- {
111
- // Language client has a disposal bug in it
112
- }
103
+ Restart = false ,
104
+ TerminateDebuggee = true
105
+ } ) . ConfigureAwait ( true ) ;
106
+ await _psesProcess . Stop ( ) . ConfigureAwait ( true ) ;
107
+ PsesDebugAdapterClient ? . Dispose ( ) ;
113
108
}
114
109
115
110
private static string NewTestFile ( string script , bool isPester = false )
@@ -147,7 +142,16 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements
147
142
return builder . ToString ( ) ;
148
143
}
149
144
150
- private static string [ ] GetLog ( ) => File . ReadLines ( s_testOutputPath ) . ToArray ( ) ;
145
+ private static async Task < string [ ] > GetLog ( )
146
+ {
147
+ while ( ! File . Exists ( s_testOutputPath ) )
148
+ {
149
+ await Task . Delay ( 1000 ) . ConfigureAwait ( true ) ;
150
+ }
151
+ // Sleep one more time after the file exists so whatever is writing can finish.
152
+ await Task . Delay ( 1000 ) . ConfigureAwait ( true ) ;
153
+ return File . ReadLines ( s_testOutputPath ) . ToArray ( ) ;
154
+ }
151
155
152
156
[ Fact ]
153
157
public void CanInitializeWithCorrectServerSettings ( )
@@ -165,14 +169,12 @@ public async Task CanLaunchScriptWithNoBreakpointsAsync()
165
169
{
166
170
string filePath = NewTestFile ( GenerateScriptFromLoggingStatements ( "works" ) ) ;
167
171
168
- await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( false ) ;
172
+ await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( true ) ;
169
173
170
- ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( false ) ;
174
+ ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( true ) ;
171
175
Assert . NotNull ( configDoneResponse ) ;
172
- await Task . Delay ( 2000 ) . ConfigureAwait ( false ) ;
173
-
174
- string [ ] log = GetLog ( ) ;
175
- Assert . Equal ( "works" , log [ 0 ] ) ;
176
+ Assert . Collection ( await GetLog ( ) . ConfigureAwait ( true ) ,
177
+ ( i ) => Assert . Equal ( "works" , i ) ) ;
176
178
}
177
179
178
180
[ SkippableFact ]
@@ -188,37 +190,32 @@ public async Task CanSetBreakpointsAsync()
188
190
"after breakpoint"
189
191
) ) ;
190
192
191
- await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( false ) ;
193
+ await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( true ) ;
192
194
193
195
// {"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}
194
196
SetBreakpointsResponse setBreakpointsResponse = await PsesDebugAdapterClient . SetBreakpoints ( new SetBreakpointsArguments
195
197
{
196
198
Source = new Source { Name = Path . GetFileName ( filePath ) , Path = filePath } ,
197
199
Breakpoints = new SourceBreakpoint [ ] { new SourceBreakpoint { Line = 2 } } ,
198
200
SourceModified = false ,
199
- } ) . ConfigureAwait ( false ) ;
201
+ } ) . ConfigureAwait ( true ) ;
200
202
201
203
Breakpoint breakpoint = setBreakpointsResponse . Breakpoints . First ( ) ;
202
204
Assert . True ( breakpoint . Verified ) ;
203
205
Assert . Equal ( filePath , breakpoint . Source . Path , ignoreCase : s_isWindows ) ;
204
206
Assert . Equal ( 2 , breakpoint . Line ) ;
205
207
206
- ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( false ) ;
208
+ ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( true ) ;
207
209
Assert . NotNull ( configDoneResponse ) ;
208
- await Task . Delay ( 2000 ) . ConfigureAwait ( false ) ;
209
-
210
- string [ ] log = GetLog ( ) ;
211
- Assert . Single ( log , ( i ) => i == "before breakpoint" ) ;
210
+ Assert . Collection ( await GetLog ( ) . ConfigureAwait ( true ) ,
211
+ ( i ) => Assert . Equal ( "before breakpoint" , i ) ) ;
212
+ File . Delete ( s_testOutputPath ) ;
212
213
213
214
ContinueResponse continueResponse = await PsesDebugAdapterClient . RequestContinue (
214
215
new ContinueArguments { ThreadId = 1 } ) . ConfigureAwait ( true ) ;
215
216
216
217
Assert . NotNull ( continueResponse ) ;
217
- await Task . Delay ( 2000 ) . ConfigureAwait ( false ) ;
218
-
219
- log = GetLog ( ) ;
220
- Assert . Collection ( log ,
221
- ( i ) => Assert . Equal ( "before breakpoint" , i ) ,
218
+ Assert . Collection ( await GetLog ( ) . ConfigureAwait ( true ) ,
222
219
( i ) => Assert . Equal ( "at breakpoint" , i ) ,
223
220
( i ) => Assert . Equal ( "after breakpoint" , i ) ) ;
224
221
}
@@ -247,24 +244,24 @@ public async Task CanStepPastSystemWindowsForms()
247
244
"Write-Host $form"
248
245
} ) ) ;
249
246
250
- await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( false ) ;
247
+ await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( true ) ;
251
248
252
249
SetFunctionBreakpointsResponse setBreakpointsResponse = await PsesDebugAdapterClient . SetFunctionBreakpoints (
253
250
new SetFunctionBreakpointsArguments
254
251
{
255
252
Breakpoints = new FunctionBreakpoint [ ]
256
253
{ new FunctionBreakpoint { Name = "Write-Host" , } }
257
- } ) . ConfigureAwait ( false ) ;
254
+ } ) . ConfigureAwait ( true ) ;
258
255
259
256
Breakpoint breakpoint = setBreakpointsResponse . Breakpoints . First ( ) ;
260
257
Assert . True ( breakpoint . Verified ) ;
261
258
262
- ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( false ) ;
259
+ ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( true ) ;
263
260
Assert . NotNull ( configDoneResponse ) ;
264
- await Task . Delay ( 2000 ) . ConfigureAwait ( false ) ;
261
+ await Task . Delay ( 5000 ) . ConfigureAwait ( true ) ;
265
262
266
263
VariablesResponse variablesResponse = await PsesDebugAdapterClient . RequestVariables (
267
- new VariablesArguments { VariablesReference = 1 } ) . ConfigureAwait ( false ) ;
264
+ new VariablesArguments { VariablesReference = 1 } ) . ConfigureAwait ( true ) ;
268
265
269
266
Variable form = variablesResponse . Variables . FirstOrDefault ( v => v . Name == "$form" ) ;
270
267
Assert . NotNull ( form ) ;
@@ -286,13 +283,12 @@ public async Task CanLaunchScriptWithCommentedLastLineAsync()
286
283
// PsesLaunchRequestArguments.Script, which is then assigned to
287
284
// DebugStateService.ScriptToLaunch in that handler, and finally used by the
288
285
// ConfigurationDoneHandler in LaunchScriptAsync.
289
- await PsesDebugAdapterClient . LaunchScript ( script , Started ) . ConfigureAwait ( false ) ;
286
+ await PsesDebugAdapterClient . LaunchScript ( script , Started ) . ConfigureAwait ( true ) ;
290
287
291
- ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( false ) ;
288
+ ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( true ) ;
292
289
Assert . NotNull ( configDoneResponse ) ;
293
- await Task . Delay ( 2000 ) . ConfigureAwait ( false ) ;
294
-
295
- Assert . Collection ( GetLog ( ) , ( i ) => Assert . Equal ( "a log statement" , i ) ) ;
290
+ Assert . Collection ( await GetLog ( ) . ConfigureAwait ( true ) ,
291
+ ( i ) => Assert . Equal ( "a log statement" , i ) ) ;
296
292
}
297
293
298
294
[ Fact ]
@@ -311,13 +307,12 @@ public async Task CanRunPesterTestFile()
311
307
}
312
308
" ) ;
313
309
314
- await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( false ) ;
315
-
316
- ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( false ) ;
310
+ await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) . ConfigureAwait ( true ) ;
311
+ ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient . RequestConfigurationDone ( new ConfigurationDoneArguments ( ) ) . ConfigureAwait ( true ) ;
317
312
Assert . NotNull ( configDoneResponse ) ;
318
- await Task . Delay ( 2000 ) . ConfigureAwait ( false ) ;
319
313
320
- Assert . Collection ( GetLog ( ) , ( i ) => Assert . Equal ( "pester" , i ) ) ;
314
+ Assert . Collection ( await GetLog ( ) . ConfigureAwait ( true ) ,
315
+ ( i ) => Assert . Equal ( "pester" , i ) ) ;
321
316
}
322
317
}
323
318
}
0 commit comments