Skip to content
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

Do not crash data collector if a extension initialize fails. #1230

Merged
merged 3 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,9 @@ private Dictionary<string, DataCollectionEnvironmentVariable> GetEnvironmentVari
var dataCollectorEnvironmentVariable = new Dictionary<string, DataCollectionEnvironmentVariable>(StringComparer.OrdinalIgnoreCase);
foreach (var dataCollectorInfo in this.RunDataCollectors.Values)
{
dataCollectorInfo.SetTestExecutionEnvironmentVariables();
try
{
dataCollectorInfo.SetTestExecutionEnvironmentVariables();
this.AddCollectorEnvironmentVariables(dataCollectorInfo, dataCollectorEnvironmentVariable);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class ProxyExecutionManagerWithDataCollection : ProxyExecutionManager
/// <summary>
/// Initializes a new instance of the <see cref="ProxyExecutionManagerWithDataCollection"/> class.
/// </summary>
/// <param name="testRequestSender">
/// <param name="requestSender">
/// Test request sender instance.
/// </param>
/// <param name="testHostManager">
Expand All @@ -44,6 +44,7 @@ public ProxyExecutionManagerWithDataCollection(IRequestData requestData, ITestRe
this.ProxyDataCollectionManager = proxyDataCollectionManager;
this.DataCollectionRunEventsHandler = new DataCollectionRunEventsHandler();
this.requestData = requestData;
this.dataCollectionEnvironmentVariables = new Dictionary<string, string>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public DataCollectionParameters BeforeTestRunStart(
ITestMessageEventHandler runEventsHandler)
{
var areTestCaseLevelEventsRequired = false;
IDictionary<string, string> environmentVariables = null;
IDictionary<string, string> environmentVariables = new Dictionary<string, string>();

var dataCollectionEventsPort = 0;
this.InvokeDataCollectionServiceAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public void BeforeTestRunStartsShouldInvokeRunEventsHandlerIfExceptionIsThrown()
var result = this.proxyDataCollectionManager.BeforeTestRunStart(true, true, mockRunEventsHandler.Object);

mockRunEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Exception of type 'System.Exception' was thrown."), Times.Once);
Assert.AreEqual(result.EnvironmentVariables, null);
Assert.AreEqual(result.AreTestCaseLevelEventsRequired, false);
Assert.AreEqual(result.DataCollectionEventsPort, 0);
Assert.AreEqual(0, result.EnvironmentVariables.Count);
Assert.AreEqual(false, result.AreTestCaseLevelEventsRequired);
Assert.AreEqual(0, result.DataCollectionEventsPort);
}

[TestMethod]
Expand Down
11 changes: 11 additions & 0 deletions test/datacollector.UnitTests/DataCollectionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ public void InitializeDataCollectorsShouldLogExceptionToMessageSinkIfInitializat
this.mockMessageSink.Verify(x => x.SendMessage(It.IsAny<DataCollectionMessageEventArgs>()), Times.Once);
}

[TestMethod]
public void InitializeDataCollectorsShouldLogExceptionToMessageSinkIfSetEnvironmentVariableFails()
{
this.mockDataCollector.As<ITestExecutionEnvironmentSpecifier>().Setup(x => x.GetTestExecutionEnvironmentVariables()).Throws<Exception>();

this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings);

Assert.AreEqual(0, this.dataCollectionManager.RunDataCollectors.Count);
this.mockMessageSink.Verify(x => x.SendMessage(It.IsAny<DataCollectionMessageEventArgs>()), Times.Once);
}

[TestMethod]
public void InitializeDataCollectorsShouldReturnFirstEnvironmentVariableIfMoreThanOneVariablesWithSameKeyIsSpecified()
{
Expand Down