@@ -189,6 +189,73 @@ public void InitializeWithDumpForHangShouldCaptureADumpOnTimeout()
189189 this . mockDataCollectionSink . Verify ( x => x . SendFileAsync ( It . Is < FileTransferInformation > ( y => y . Path == dumpFile ) ) , Times . Once ) ;
190190 }
191191
192+ /// <summary>
193+ /// Initializing with collect dump for hang should kill test host process even if an error
194+ /// occurs during capturing the dump. Basically it should not throw.
195+ /// </summary>
196+ [ TestMethod ]
197+ public void InitializeWithDumpForHangShouldCaptureKillTestHostOnTimeoutEvenIfGetDumpFileFails ( )
198+ {
199+ this . blameDataCollector = new TestableBlameCollector (
200+ this . mockBlameReaderWriter . Object ,
201+ this . mockProcessDumpUtility . Object ,
202+ null ,
203+ this . mockFileHelper . Object ) ;
204+
205+ var hangBasedDumpcollected = new ManualResetEventSlim ( ) ;
206+
207+ this . mockFileHelper . Setup ( x => x . Exists ( It . Is < string > ( y => y == "abc_hang.dmp" ) ) ) . Returns ( true ) ;
208+ this . mockFileHelper . Setup ( x => x . GetFullPath ( It . Is < string > ( y => y == "abc_hang.dmp" ) ) ) . Returns ( "abc_hang.dmp" ) ;
209+ this . mockProcessDumpUtility . Setup ( x => x . StartHangBasedProcessDump ( It . IsAny < int > ( ) , It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < bool > ( ) ) ) ;
210+ this . mockProcessDumpUtility . Setup ( x => x . GetDumpFile ( ) ) . Callback ( ( ) => hangBasedDumpcollected . Set ( ) ) . Throws ( new Exception ( "Some exception" ) ) ;
211+
212+ this . blameDataCollector . Initialize (
213+ this . GetDumpConfigurationElement ( false , false , true , 0 ) ,
214+ this . mockDataColectionEvents . Object ,
215+ this . mockDataCollectionSink . Object ,
216+ this . mockLogger . Object ,
217+ this . context ) ;
218+
219+ hangBasedDumpcollected . Wait ( 1000 ) ;
220+ this . mockProcessDumpUtility . Verify ( x => x . StartHangBasedProcessDump ( It . IsAny < int > ( ) , It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < bool > ( ) ) , Times . Once ) ;
221+ this . mockProcessDumpUtility . Verify ( x => x . GetDumpFile ( ) , Times . Once ) ;
222+ }
223+
224+ /// <summary>
225+ /// Initializing with collect dump for hang should kill test host process even if an error
226+ /// occurs during attaching it as a datacollector attachment. Basically it should not throw.
227+ /// </summary>
228+ [ TestMethod ]
229+ public void InitializeWithDumpForHangShouldCaptureKillTestHostOnTimeoutEvenIfAttachingDumpFails ( )
230+ {
231+ this . blameDataCollector = new TestableBlameCollector (
232+ this . mockBlameReaderWriter . Object ,
233+ this . mockProcessDumpUtility . Object ,
234+ null ,
235+ this . mockFileHelper . Object ) ;
236+
237+ var dumpFile = "abc_hang.dmp" ;
238+ var hangBasedDumpcollected = new ManualResetEventSlim ( ) ;
239+
240+ this . mockFileHelper . Setup ( x => x . Exists ( It . Is < string > ( y => y == "abc_hang.dmp" ) ) ) . Returns ( true ) ;
241+ this . mockFileHelper . Setup ( x => x . GetFullPath ( It . Is < string > ( y => y == "abc_hang.dmp" ) ) ) . Returns ( "abc_hang.dmp" ) ;
242+ this . mockProcessDumpUtility . Setup ( x => x . StartHangBasedProcessDump ( It . IsAny < int > ( ) , It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < bool > ( ) ) ) ;
243+ this . mockProcessDumpUtility . Setup ( x => x . GetDumpFile ( ) ) . Returns ( dumpFile ) ;
244+ this . mockDataCollectionSink . Setup ( x => x . SendFileAsync ( It . IsAny < FileTransferInformation > ( ) ) ) . Callback ( ( ) => hangBasedDumpcollected . Set ( ) ) . Throws ( new Exception ( "Some other exception" ) ) ;
245+
246+ this . blameDataCollector . Initialize (
247+ this . GetDumpConfigurationElement ( false , false , true , 0 ) ,
248+ this . mockDataColectionEvents . Object ,
249+ this . mockDataCollectionSink . Object ,
250+ this . mockLogger . Object ,
251+ this . context ) ;
252+
253+ hangBasedDumpcollected . Wait ( 1000 ) ;
254+ this . mockProcessDumpUtility . Verify ( x => x . StartHangBasedProcessDump ( It . IsAny < int > ( ) , It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < bool > ( ) ) , Times . Once ) ;
255+ this . mockProcessDumpUtility . Verify ( x => x . GetDumpFile ( ) , Times . Once ) ;
256+ this . mockDataCollectionSink . Verify ( x => x . SendFileAsync ( It . Is < FileTransferInformation > ( y => y . Path == dumpFile ) ) , Times . Once ) ;
257+ }
258+
192259 /// <summary>
193260 /// The trigger session ended handler should write to file if test start count is greater.
194261 /// </summary>
@@ -593,7 +660,7 @@ public void TriggerTestHostLaunchedHandlerShouldCatchTestPlatFormExceptionsAndRe
593660 }
594661
595662 /// <summary>
596- /// The trigger test host launcehd handler should not break if start process dump throws unknown exceptions and report message with stack trace
663+ /// The trigger test host launched handler should not break if start process dump throws unknown exceptions and report message with stack trace
597664 /// </summary>
598665 [ TestMethod ]
599666 public void TriggerTestHostLaunchedHandlerShouldCatchAllUnexpectedExceptionsAndReportMessageWithStackTrace ( )
0 commit comments