-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blame Sequence File Changes #1716
Changes from 5 commits
353998e
80a2cae
4b45407
d155f3f
908297c
abf651d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ public class BlameCollector : DataCollector, ITestExecutionEnvironmentSpecifier | |
private DataCollectionEvents events; | ||
private DataCollectionLogger logger; | ||
private IProcessDumpUtility processDumpUtility; | ||
private List<TestCase> testSequence; | ||
private List<Guid> testSequence; | ||
private Dictionary<Guid, BlameTestObject> testObjectDictionary; | ||
private IBlameReaderWriter blameReaderWriter; | ||
private XmlElement configurationElement; | ||
private int testStartCount; | ||
|
@@ -88,7 +89,8 @@ public override void Initialize( | |
this.dataCollectionSink = dataSink; | ||
this.context = environmentContext; | ||
this.configurationElement = configurationElement; | ||
this.testSequence = new List<TestCase>(); | ||
this.testSequence = new List<Guid>(); | ||
this.testObjectDictionary = new Dictionary<Guid, BlameTestObject>(); | ||
this.logger = logger; | ||
|
||
// Subscribing to events | ||
|
@@ -155,7 +157,15 @@ private void EventsTestCaseStart(object sender, TestCaseStartEventArgs e) | |
EqtTrace.Info("Blame Collector : Test Case Start"); | ||
} | ||
|
||
this.testSequence.Add(e.TestElement); | ||
var blameTestObject = new BlameTestObject(e.TestElement); | ||
|
||
// Add guid to list of test sequence to maintain the order. | ||
this.testSequence.Add(blameTestObject.Id); | ||
|
||
// Add the test object to the dictionary. | ||
this.testObjectDictionary.Add(blameTestObject.Id, blameTestObject); | ||
|
||
// Increment test start count. | ||
this.testStartCount++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do we still need this>? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will have to check for entire dictionary if any test remains incomplete to decide if sequence is to be written to file. This makes an easier check. |
||
} | ||
|
||
|
@@ -172,6 +182,12 @@ private void EventsTestCaseEnd(object sender, TestCaseEndEventArgs e) | |
} | ||
|
||
this.testEndCount++; | ||
|
||
// Update the test object in the dictionary as the test has completed. | ||
if (this.testObjectDictionary.ContainsKey(e.TestElement.Id)) | ||
{ | ||
this.testObjectDictionary[e.TestElement.Id].IsCompleted = true; | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
@@ -192,7 +208,7 @@ private void SessionEnded_Handler(object sender, SessionEndEventArgs args) | |
if (this.testStartCount > this.testEndCount) | ||
{ | ||
var filepath = Path.Combine(this.GetResultsDirectory(), Constants.AttachmentFileName + "_" + this.attachmentGuid); | ||
filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, filepath); | ||
filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, this.testObjectDictionary, filepath); | ||
var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true); | ||
this.dataCollectionSink.SendFileAsync(fileTranferInformation); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.TestPlatform.Extensions.BlameDataCollector | ||
{ | ||
using System; | ||
using System.IO; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; | ||
|
||
public class BlameTestObject | ||
{ | ||
private Guid id; | ||
private string fullyQualifiedName; | ||
private string source; | ||
private bool isCompleted; | ||
private string displayName; | ||
|
||
#region Constructor | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BlameTestObject"/> class. | ||
/// </summary> | ||
public BlameTestObject() | ||
{ | ||
// Default constructor | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BlameTestObject"/> class. | ||
/// </summary> | ||
/// <param name="fullyQualifiedName"> | ||
/// Fully qualified name of the test case. | ||
/// </param> | ||
/// <param name="executorUri"> | ||
/// The Uri of the executor to use for running this test. | ||
/// </param> | ||
/// <param name="source"> | ||
/// Test container source from which the test is discovered. | ||
/// </param> | ||
public BlameTestObject(string fullyQualifiedName, Uri executorUri, string source) | ||
{ | ||
ValidateArg.NotNullOrEmpty(fullyQualifiedName, "fullyQualifiedName"); | ||
ValidateArg.NotNull(executorUri, "executorUri"); | ||
ValidateArg.NotNullOrEmpty(source, "source"); | ||
|
||
this.Id = Guid.Empty; | ||
this.FullyQualifiedName = fullyQualifiedName; | ||
this.ExecutorUri = executorUri; | ||
this.Source = source; | ||
this.IsCompleted = false; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BlameTestObject"/> class. | ||
/// </summary> | ||
/// <param name="testCase"> | ||
/// The test case | ||
/// </param> | ||
public BlameTestObject(TestCase testCase) | ||
{ | ||
this.Id = testCase.Id; | ||
this.FullyQualifiedName = testCase.FullyQualifiedName; | ||
this.ExecutorUri = testCase.ExecutorUri; | ||
this.Source = testCase.Source; | ||
this.DisplayName = testCase.DisplayName; | ||
this.IsCompleted = false; | ||
} | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets or sets the id of the test case. | ||
/// </summary> | ||
public Guid Id | ||
{ | ||
get | ||
{ | ||
return this.id; | ||
} | ||
|
||
set | ||
{ | ||
this.id = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the fully qualified name of the test case. | ||
/// </summary> | ||
public string FullyQualifiedName | ||
{ | ||
get | ||
{ | ||
return this.fullyQualifiedName; | ||
} | ||
|
||
set | ||
{ | ||
this.fullyQualifiedName = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the Uri of the Executor to use for running this test. | ||
/// </summary> | ||
public Uri ExecutorUri | ||
{ | ||
get; set; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the test container source from which the test is discovered. | ||
/// </summary> | ||
public string Source | ||
{ | ||
get | ||
{ | ||
return this.source; | ||
} | ||
|
||
set | ||
{ | ||
this.source = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether test case is completed or not. | ||
/// </summary> | ||
public bool IsCompleted | ||
{ | ||
get | ||
{ | ||
return this.isCompleted; | ||
} | ||
|
||
set | ||
{ | ||
this.isCompleted = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the display name of the test case | ||
/// </summary> | ||
public string DisplayName | ||
{ | ||
get | ||
{ | ||
return this.displayName; | ||
} | ||
|
||
set | ||
{ | ||
this.displayName = value; | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
namespace Microsoft.TestPlatform.Extensions.BlameDataCollector | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Xml; | ||
|
@@ -46,18 +47,23 @@ protected XmlReaderWriter(IFileHelper fileHelper) | |
#endregion | ||
|
||
/// <summary> | ||
/// Adds tests to document and saves document to file | ||
/// Writes test Sequence to file. | ||
/// Protected for testing purposes | ||
/// </summary> | ||
/// <param name="testSequence"> | ||
/// The test Sequence. | ||
/// Sequence of Guids | ||
/// </param> | ||
/// <param name="testObjectDictionary"> | ||
/// Dictionary of test objects | ||
/// </param> | ||
/// <param name="filePath"> | ||
/// The file Path. | ||
/// </param> | ||
/// <returns>File path</returns> | ||
public string WriteTestSequence(List<TestCase> testSequence, string filePath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
check for outcome/result There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no outcome field in TestCase object. |
||
public string WriteTestSequence(List<Guid> testSequence, Dictionary<Guid, BlameTestObject> testObjectDictionary, string filePath) | ||
{ | ||
ValidateArg.NotNull(testSequence, nameof(testSequence)); | ||
ValidateArg.NotNull(testObjectDictionary, nameof(testObjectDictionary)); | ||
ValidateArg.NotNullOrEmpty(filePath, nameof(filePath)); | ||
|
||
filePath = filePath + ".xml"; | ||
|
@@ -68,13 +74,20 @@ public string WriteTestSequence(List<TestCase> testSequence, string filePath) | |
var blameTestRoot = xmlDocument.CreateElement(Constants.BlameRootNode); | ||
xmlDocument.AppendChild(xmlDeclaration); | ||
|
||
foreach (var testCase in testSequence) | ||
foreach (var testGuid in testSequence) | ||
{ | ||
var testElement = xmlDocument.CreateElement(Constants.BlameTestNode); | ||
testElement.SetAttribute(Constants.TestNameAttribute, testCase.FullyQualifiedName); | ||
testElement.SetAttribute(Constants.TestSourceAttribute, testCase.Source); | ||
if (testObjectDictionary.ContainsKey(testGuid)) | ||
{ | ||
var testObject = testObjectDictionary[testGuid]; | ||
|
||
blameTestRoot.AppendChild(testElement); | ||
var testElement = xmlDocument.CreateElement(Constants.BlameTestNode); | ||
testElement.SetAttribute(Constants.TestNameAttribute, testObject.FullyQualifiedName); | ||
testElement.SetAttribute(Constants.TestDisplayNameAttribute, testObject.DisplayName); | ||
testElement.SetAttribute(Constants.TestSourceAttribute, testObject.Source); | ||
testElement.SetAttribute(Constants.TestCompletedAttribute, testObject.IsCompleted.ToString()); | ||
|
||
blameTestRoot.AppendChild(testElement); | ||
} | ||
} | ||
|
||
xmlDocument.AppendChild(blameTestRoot); | ||
|
@@ -91,7 +104,7 @@ public string WriteTestSequence(List<TestCase> testSequence, string filePath) | |
/// </summary> | ||
/// <param name="filePath">The path of test sequence file</param> | ||
/// <returns>Test Case List</returns> | ||
public List<TestCase> ReadTestSequence(string filePath) | ||
public List<BlameTestObject> ReadTestSequence(string filePath) | ||
{ | ||
ValidateArg.NotNull(filePath, nameof(filePath)); | ||
|
||
|
@@ -100,7 +113,7 @@ public List<TestCase> ReadTestSequence(string filePath) | |
throw new FileNotFoundException(); | ||
} | ||
|
||
var testCaseList = new List<TestCase>(); | ||
var testCaseList = new List<BlameTestObject>(); | ||
try | ||
{ | ||
// Reading test sequence | ||
|
@@ -113,11 +126,13 @@ public List<TestCase> ReadTestSequence(string filePath) | |
var root = xmlDocument.LastChild; | ||
foreach (XmlNode node in root) | ||
{ | ||
var testCase = new TestCase | ||
var testCase = new BlameTestObject | ||
{ | ||
FullyQualifiedName = | ||
node.Attributes[Constants.TestNameAttribute].Value, | ||
Source = node.Attributes[Constants.TestSourceAttribute].Value | ||
Source = node.Attributes[Constants.TestSourceAttribute].Value, | ||
DisplayName = node.Attributes[Constants.TestDisplayNameAttribute].Value, | ||
IsCompleted = node.Attributes[Constants.TestCompletedAttribute].Value == "True" ? true : false | ||
}; | ||
testCaseList.Add(testCase); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make dict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dictionary and list used.