Skip to content

Commit 131ca14

Browse files
authored
Users/shreyas r msft/added env var support for blame results directory path (#2216)
* Added env var support to blame test results directory path and fixed blame aborting without killing the test host process on hang timeout when there is an error with dump * Added tests
1 parent f0cd370 commit 131ca14

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public override void Initialize(
126126
{
127127
var collectDumpNode = this.configurationElement[Constants.DumpModeKey];
128128
this.collectProcessDumpOnTrigger = collectDumpNode != null;
129+
129130
if (this.collectProcessDumpOnTrigger)
130131
{
131132
this.ValidateAndAddTriggerBasedProcessDumpParameters(collectDumpNode);
@@ -198,8 +199,9 @@ private void CollectDumpAndAbortTesthost()
198199
EqtTrace.Error("BlameCollector.CollectDumpAndAbortTesthost: blame:CollectDumpOnHang was enabled but dump file was not generated.");
199200
}
200201
}
201-
catch (FileNotFoundException ex)
202+
catch (Exception ex)
202203
{
204+
// Eat up any exception here and log it but proceed with killing the test host process.
203205
EqtTrace.Error(ex);
204206
}
205207

@@ -485,7 +487,8 @@ private string GetResultsDirectory()
485487
{
486488
XmlElement resultsDirectoryElement = this.configurationElement["ResultsDirectory"];
487489
string resultsDirectory = resultsDirectoryElement != null ? resultsDirectoryElement.InnerText : string.Empty;
488-
return resultsDirectory;
490+
491+
return Environment.ExpandEnvironmentVariables(resultsDirectory);
489492
}
490493
catch (NullReferenceException exception)
491494
{

test/Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests/BlameCollectorTests.cs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)