@@ -80,20 +80,20 @@ public async Task InitializeAsync()
80
80
public async Task DisposeAsync ( )
81
81
{
82
82
debugService . Abort ( ) ;
83
- debuggerStoppedQueue . Dispose ( ) ;
84
83
await Task . Run ( psesHost . StopAsync ) ;
84
+ debuggerStoppedQueue . Dispose ( ) ;
85
85
}
86
86
87
87
/// <summary>
88
- /// This event handler lets us test that the debugger stopped or paused as expected. It will
89
- /// deadlock if called in the PSES Pipeline Thread, which can easily happen in this test
90
- /// code when methods on <see cref="debugService" /> are called. Hence we treat this test
91
- /// code like UI code and use 'ConfigureAwait(true)' or 'Task.Run(...)' to ensure we stay
92
- /// OFF the pipeline thread.
88
+ /// This event handler lets us test that the debugger stopped or paused
89
+ /// as expected. It will deadlock if called in the PSES Pipeline Thread.
90
+ /// Hence we use 'Task.Run(...)' when accessing the queue to ensure we
91
+ /// stay OFF the pipeline thread.
93
92
/// </summary>
94
93
/// <param name="sender"></param>
95
94
/// <param name="e"></param>
96
- private void OnDebuggerStopped ( object sender , DebuggerStoppedEventArgs e ) => debuggerStoppedQueue . Add ( e ) ;
95
+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Usage" , "VSTHRD110:Observe result of async calls" , Justification = "This intentionally fires and forgets on another thread." ) ]
96
+ private void OnDebuggerStopped ( object sender , DebuggerStoppedEventArgs e ) => Task . Run ( ( ) => debuggerStoppedQueue . Add ( e ) ) ;
97
97
98
98
private ScriptFile GetDebugScript ( string fileName ) => workspace . GetFile ( TestUtilities . GetSharedPath ( Path . Combine ( "Debugging" , fileName ) ) ) ;
99
99
@@ -116,20 +116,20 @@ private Task ExecuteScriptFileAsync(string scriptFilePath, params string[] args)
116
116
117
117
private Task ExecuteVariableScriptFileAsync ( ) => ExecuteScriptFileAsync ( variableScriptFile . FilePath ) ;
118
118
119
- private void AssertDebuggerPaused ( )
119
+ private async Task AssertDebuggerPaused ( )
120
120
{
121
121
using CancellationTokenSource cts = new ( 60000 ) ;
122
- DebuggerStoppedEventArgs eventArgs = debuggerStoppedQueue . Take ( cts . Token ) ;
122
+ DebuggerStoppedEventArgs eventArgs = await Task . Run ( ( ) => debuggerStoppedQueue . Take ( cts . Token ) ) ;
123
123
Assert . Empty ( eventArgs . OriginalEvent . Breakpoints ) ;
124
124
}
125
125
126
- private void AssertDebuggerStopped (
126
+ private async Task AssertDebuggerStopped (
127
127
string scriptPath = "" ,
128
128
int lineNumber = - 1 ,
129
129
CommandBreakpointDetails commandBreakpointDetails = default )
130
130
{
131
- using CancellationTokenSource cts = new ( 60000 ) ;
132
- DebuggerStoppedEventArgs eventArgs = debuggerStoppedQueue . Take ( cts . Token ) ;
131
+ using CancellationTokenSource cts = new ( 30000 ) ;
132
+ DebuggerStoppedEventArgs eventArgs = await Task . Run ( ( ) => debuggerStoppedQueue . Take ( cts . Token ) ) ;
133
133
134
134
Assert . True ( psesHost . DebugContext . IsStopped ) ;
135
135
@@ -174,8 +174,8 @@ await debugService.SetCommandBreakpointsAsync(
174
174
Task < IReadOnlyList < int > > executeTask = psesHost . ExecutePSCommandAsync < int > (
175
175
new PSCommand ( ) . AddScript ( "Get-Random -SetSeed 42 -Maximum 100" ) , CancellationToken . None ) ;
176
176
177
- AssertDebuggerStopped ( "" , 1 ) ;
178
- await Task . Run ( debugService . Continue ) ;
177
+ await AssertDebuggerStopped ( "" , 1 ) ;
178
+ debugService . Continue ( ) ;
179
179
Assert . Equal ( 17 , ( await executeTask ) [ 0 ] ) ;
180
180
181
181
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) ;
@@ -216,7 +216,7 @@ public async Task DebuggerAcceptsScriptArgs(string[] args)
216
216
217
217
Task _ = ExecuteScriptFileAsync ( oddPathScriptFile . FilePath , args ) ;
218
218
219
- AssertDebuggerStopped ( oddPathScriptFile . FilePath , 3 ) ;
219
+ await AssertDebuggerStopped ( oddPathScriptFile . FilePath , 3 ) ;
220
220
221
221
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
222
222
@@ -283,7 +283,7 @@ public async Task DebuggerStopsOnFunctionBreakpoints()
283
283
new [ ] { CommandBreakpointDetails . Create ( "Write-Host" ) } ) ;
284
284
285
285
Task _ = ExecuteDebugFileAsync ( ) ;
286
- AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
286
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
287
287
288
288
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
289
289
@@ -294,8 +294,8 @@ public async Task DebuggerStopsOnFunctionBreakpoints()
294
294
Assert . Equal ( "1" , i . ValueString ) ;
295
295
296
296
// The function breakpoint should fire the next time through the loop.
297
- await Task . Run ( debugService . Continue ) ;
298
- AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
297
+ debugService . Continue ( ) ;
298
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
299
299
300
300
variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
301
301
@@ -350,9 +350,9 @@ await debugService.SetLineBreakpointsAsync(
350
350
} ) ;
351
351
352
352
Task _ = ExecuteDebugFileAsync ( ) ;
353
- AssertDebuggerStopped ( debugScriptFile . FilePath , 5 ) ;
354
- await Task . Run ( debugService . Continue ) ;
355
- AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
353
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 5 ) ;
354
+ debugService . Continue ( ) ;
355
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
356
356
}
357
357
358
358
[ Fact ]
@@ -368,7 +368,7 @@ await debugService.SetLineBreakpointsAsync(
368
368
} ) ;
369
369
370
370
Task _ = ExecuteDebugFileAsync ( ) ;
371
- AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
371
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
372
372
373
373
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
374
374
@@ -380,8 +380,8 @@ await debugService.SetLineBreakpointsAsync(
380
380
381
381
// The conditional breakpoint should not fire again, until the value of
382
382
// i reaches breakpointValue2.
383
- await Task . Run ( debugService . Continue ) ;
384
- AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
383
+ debugService . Continue ( ) ;
384
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 7 ) ;
385
385
386
386
variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
387
387
@@ -404,7 +404,7 @@ await debugService.SetLineBreakpointsAsync(
404
404
} ) ;
405
405
406
406
Task _ = ExecuteDebugFileAsync ( ) ;
407
- AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
407
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
408
408
409
409
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
410
410
@@ -425,7 +425,7 @@ await debugService.SetLineBreakpointsAsync(
425
425
new [ ] { BreakpointDetails . Create ( debugScriptFile . FilePath , 6 , null , "$i % 2 -eq 0" , $ "{ hitCount } ") } ) ;
426
426
427
427
Task _ = ExecuteDebugFileAsync ( ) ;
428
- AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
428
+ await AssertDebuggerStopped ( debugScriptFile . FilePath , 6 ) ;
429
429
430
430
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
431
431
@@ -493,18 +493,16 @@ public async Task DebuggerBreaksWhenRequested()
493
493
IReadOnlyList < LineBreakpoint > confirmedBreakpoints = await GetConfirmedBreakpoints ( debugScriptFile ) ;
494
494
Assert . Empty ( confirmedBreakpoints ) ;
495
495
Task _ = ExecuteDebugFileAsync ( ) ;
496
- // NOTE: This must be run on a separate thread so the async event handlers can fire.
497
- await Task . Run ( debugService . Break ) ;
498
- AssertDebuggerPaused ( ) ;
496
+ debugService . Break ( ) ;
497
+ await AssertDebuggerPaused ( ) ;
499
498
}
500
499
501
500
[ Fact ]
502
501
public async Task DebuggerRunsCommandsWhileStopped ( )
503
502
{
504
503
Task _ = ExecuteDebugFileAsync ( ) ;
505
- // NOTE: This must be run on a separate thread so the async event handlers can fire.
506
- await Task . Run ( debugService . Break ) ;
507
- AssertDebuggerPaused ( ) ;
504
+ debugService . Break ( ) ;
505
+ await AssertDebuggerPaused ( ) ;
508
506
509
507
// Try running a command from outside the pipeline thread
510
508
Task < IReadOnlyList < int > > executeTask = psesHost . ExecutePSCommandAsync < int > (
@@ -524,7 +522,7 @@ await debugService.SetCommandBreakpointsAsync(
524
522
525
523
ScriptFile testScript = GetDebugScript ( "PSDebugContextTest.ps1" ) ;
526
524
Task _ = ExecuteScriptFileAsync ( testScript . FilePath ) ;
527
- AssertDebuggerStopped ( testScript . FilePath , 11 ) ;
525
+ await AssertDebuggerStopped ( testScript . FilePath , 11 ) ;
528
526
529
527
VariableDetails prompt = await debugService . EvaluateExpressionAsync ( "prompt" , false , CancellationToken . None ) ;
530
528
Assert . Equal ( "True > " , prompt . ValueString ) ;
@@ -549,7 +547,7 @@ await debugService.SetCommandBreakpointsAsync(
549
547
NullLoggerFactory . Instance , null , debugService , null , null , psesHost , workspace , null , psesHost ) ;
550
548
551
549
Task _ = configurationDoneHandler . LaunchScriptAsync ( scriptPath ) ;
552
- AssertDebuggerStopped ( scriptPath , 1 ) ;
550
+ await AssertDebuggerStopped ( scriptPath , 1 ) ;
553
551
554
552
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . CommandVariablesName ) ;
555
553
VariableDetailsBase myInvocation = Array . Find ( variables , v => v . Name == "$MyInvocation" ) ;
@@ -627,7 +625,7 @@ await debugService.SetLineBreakpointsAsync(
627
625
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 8 ) } ) ;
628
626
629
627
Task _ = ExecuteVariableScriptFileAsync ( ) ;
630
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
628
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
631
629
632
630
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
633
631
@@ -645,7 +643,7 @@ await debugService.SetLineBreakpointsAsync(
645
643
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 21 ) } ) ;
646
644
647
645
Task _ = ExecuteVariableScriptFileAsync ( ) ;
648
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
646
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
649
647
650
648
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
651
649
@@ -695,7 +693,7 @@ await debugService.SetLineBreakpointsAsync(
695
693
new [ ] { BreakpointDetails . Create ( variableScriptFile . FilePath , 14 ) } ) ;
696
694
697
695
Task _ = ExecuteVariableScriptFileAsync ( ) ;
698
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
696
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
699
697
700
698
VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
701
699
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -721,8 +719,8 @@ await debugService.SetLineBreakpointsAsync(
721
719
722
720
// The above just tests that the debug service returns the correct new value string.
723
721
// Let's step the debugger and make sure the values got set to the new values.
724
- await Task . Run ( debugService . StepOver ) ;
725
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
722
+ debugService . StepOver ( ) ;
723
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
726
724
727
725
// Test set of a local string variable (not strongly typed)
728
726
variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -749,7 +747,7 @@ await debugService.SetLineBreakpointsAsync(
749
747
750
748
// Execute the script and wait for the breakpoint to be hit
751
749
Task _ = ExecuteVariableScriptFileAsync ( ) ;
752
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
750
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
753
751
754
752
VariableScope [ ] scopes = debugService . GetVariableScopes ( 0 ) ;
755
753
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -777,8 +775,8 @@ await debugService.SetLineBreakpointsAsync(
777
775
778
776
// The above just tests that the debug service returns the correct new value string.
779
777
// Let's step the debugger and make sure the values got set to the new values.
780
- await Task . Run ( debugService . StepOver ) ;
781
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
778
+ debugService . StepOver ( ) ;
779
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
782
780
783
781
// Test set of a local string variable (not strongly typed but force conversion)
784
782
variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
@@ -805,7 +803,7 @@ await debugService.SetLineBreakpointsAsync(
805
803
806
804
// Execute the script and wait for the breakpoint to be hit
807
805
Task _ = ExecuteVariableScriptFileAsync ( ) ;
808
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
806
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
809
807
810
808
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) ;
811
809
VariableDetailsBase [ ] variables = await debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id , CancellationToken . None ) ;
@@ -825,7 +823,7 @@ await debugService.SetLineBreakpointsAsync(
825
823
826
824
// Execute the script and wait for the breakpoint to be hit
827
825
Task _ = ExecuteVariableScriptFileAsync ( ) ;
828
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
826
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
829
827
830
828
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) ;
831
829
VariableDetailsBase [ ] variables = await debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id , CancellationToken . None ) ;
@@ -858,7 +856,7 @@ await debugService.SetLineBreakpointsAsync(
858
856
859
857
// Execute the script and wait for the breakpoint to be hit
860
858
Task _ = ExecuteVariableScriptFileAsync ( ) ;
861
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
859
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
862
860
863
861
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) ;
864
862
VariableDetailsBase [ ] variables = await debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id , CancellationToken . None ) ;
@@ -878,7 +876,7 @@ await debugService.SetLineBreakpointsAsync(
878
876
879
877
// Execute the script and wait for the breakpoint to be hit
880
878
Task _ = ExecuteVariableScriptFileAsync ( ) ;
881
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
879
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
882
880
883
881
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) ;
884
882
VariableDetailsBase [ ] variables = await debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id , CancellationToken . None ) ;
@@ -905,7 +903,7 @@ public async Task DebuggerEnumerableShowsRawView()
905
903
906
904
// Execute the script and wait for the breakpoint to be hit
907
905
Task _ = ExecuteVariableScriptFileAsync ( ) ;
908
- AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
906
+ await AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
909
907
910
908
VariableDetailsBase simpleArrayVar = Array . Find (
911
909
await GetVariables ( VariableContainerDetails . ScriptScopeName ) ,
@@ -962,7 +960,7 @@ public async Task DebuggerDictionaryShowsRawView()
962
960
963
961
// Execute the script and wait for the breakpoint to be hit
964
962
Task _ = ExecuteVariableScriptFileAsync ( ) ;
965
- AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
963
+ await AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
966
964
967
965
VariableDetailsBase simpleDictionaryVar = Array . Find (
968
966
await GetVariables ( VariableContainerDetails . ScriptScopeName ) ,
@@ -1025,7 +1023,7 @@ public async Task DebuggerDerivedDictionaryPropertyInRawView()
1025
1023
1026
1024
// Execute the script and wait for the breakpoint to be hit
1027
1025
Task _ = ExecuteVariableScriptFileAsync ( ) ;
1028
- AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
1026
+ await AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
1029
1027
1030
1028
VariableDetailsBase sortedDictionaryVar = Array . Find (
1031
1029
await GetVariables ( VariableContainerDetails . ScriptScopeName ) ,
@@ -1074,7 +1072,7 @@ await debugService.SetLineBreakpointsAsync(
1074
1072
1075
1073
// Execute the script and wait for the breakpoint to be hit
1076
1074
Task _ = ExecuteVariableScriptFileAsync ( ) ;
1077
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
1075
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
1078
1076
1079
1077
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) ;
1080
1078
VariableDetailsBase [ ] variables = await debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id , CancellationToken . None ) ;
@@ -1103,7 +1101,7 @@ await debugService.SetLineBreakpointsAsync(
1103
1101
1104
1102
// Execute the script and wait for the breakpoint to be hit
1105
1103
Task _ = ExecuteVariableScriptFileAsync ( ) ;
1106
- AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
1104
+ await AssertDebuggerStopped ( variableScriptFile . FilePath ) ;
1107
1105
1108
1106
StackFrameDetails [ ] stackFrames = await debugService . GetStackFramesAsync ( ) ;
1109
1107
VariableDetailsBase [ ] variables = await debugService . GetVariables ( stackFrames [ 0 ] . AutoVariables . Id , CancellationToken . None ) ;
@@ -1132,7 +1130,7 @@ await debugService.SetCommandBreakpointsAsync(
1132
1130
1133
1131
ScriptFile testScript = GetDebugScript ( "GetChildItemTest.ps1" ) ;
1134
1132
Task _ = ExecuteScriptFileAsync ( testScript . FilePath ) ;
1135
- AssertDebuggerStopped ( testScript . FilePath , 2 ) ;
1133
+ await AssertDebuggerStopped ( testScript . FilePath , 2 ) ;
1136
1134
1137
1135
VariableDetailsBase [ ] variables = await GetVariables ( VariableContainerDetails . LocalScopeName ) ;
1138
1136
VariableDetailsBase var = Array . Find ( variables , v => v . Name == "$file" ) ;
@@ -1152,7 +1150,7 @@ public async Task DebuggerToStringShouldMarshallToPipeline()
1152
1150
1153
1151
// Execute the script and wait for the breakpoint to be hit
1154
1152
Task _ = ExecuteVariableScriptFileAsync ( ) ;
1155
- AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
1153
+ await AssertDebuggerStopped ( commandBreakpointDetails : breakpoint ) ;
1156
1154
1157
1155
VariableDetailsBase [ ] vars = await GetVariables ( VariableContainerDetails . ScriptScopeName ) ;
1158
1156
VariableDetailsBase customToStrings = Array . Find ( vars , i => i . Name is "$CustomToStrings" ) ;
0 commit comments