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

make testplatform compatible with old testhost #971

Merged
merged 13 commits into from
Aug 4, 2017

Conversation

Faizan2304
Copy link
Contributor

@Faizan2304 Faizan2304 commented Aug 2, 2017

Issue

**Issue1: ** TestHost of version 15.0.0-preview throw exception if any unknown runsettings node (for example TestSessionTimeout is present in runsettings and it got stuck forever.

**issue2: ** If testhost throw exception before starting test run, it doesn't send any testruncomplete event or it doesn't abort process. As a result of it vstest.console keep waiting forever for testhost to send testruncomplete.

#970

Fix

Don't send these newly added runsettings (which are unknown to old testhosts ) to old test hosts.

@@ -103,6 +105,45 @@ public static void UpdateCollectSourceInformation(XPathNavigator runSettingsNavi
}

/// <summary>
/// Remove the <c>RunConfiguration.DesignMode</c> value for a run settings.
/// </summary>
public static void RemoveDesignMode(XPathNavigator runSettingsNavigator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY: Can we have generalize method here, rather than one method for each element?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cant, generalized method (RemoveNodeFromRunConfiguration) is getting called from this method. We cant generalize because in that case we have to pass full path(RunSettings/RunConfiguration/DesignMode) and name of node to delete it and we want to have those info in this class only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in next commit

document.Load(reader);

var navigator = document.CreateNavigator();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than removing new ones, Can we just keep old ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically it seems right but i think it will be little big work.

@@ -87,6 +87,11 @@ public void Initialize(IEnumerable<string> pathToAdditionalExtensions)

this.activeTestRun.RunTests();
}
catch(Exception e)
{
this.testRunEventsHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass e.ToString(), Having stacktrace helps finding RC quickly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in next commit.

}

[TestMethod]
public void RemoveDesignModeShouldRemoveDesignModeNode()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests seems to be redundant. Didn't DataTestMethod covering the same functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No DataTestMethod (RemoveNodeFromRunConfigurationShouldNotModifyXmlIfNavigatorIsNotAtRootNode) is covering the scenario where we are sending wrong navigator, that is its a negative test. RemoveDesignModeShouldRemoveDesignModeNode is positive test which are checking the actual functionality of function RemoveDesignMode

var listOfInValidRunConfigurationSettings = new List<string>();

// These are the list of valid RunConfiguration setting name which old testhost understand.
var listOfValidRunConfigurationSettings = new List<string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Set here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in next commit

string settingsName = string.Join(", ", listOfInValidRunConfigurationSettings);
EqtTrace.Warning(string.Format("InferRunSettingsHelper.MakeRunsettingsCompatible: Removing the following settings: {0} from RunSettings file. To use those settings please move to latest version of Microsoft.NET.Test.Sdk", settingsName));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove additional empty lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!!

@@ -110,6 +110,11 @@ public DotnetTestHostManager()
internal virtual bool IsVersionCheckRequired => !this.hostPackageVersion.StartsWith("15.0.0");

/// <summary>
/// Gets a value indicating whether the test host supports protocol version check
/// </summary>
internal virtual bool TestHostCannotHandleNewRunSettingsNode => this.hostPackageVersion.StartsWith("15.0.0-preview");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be virtual?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no need, i will remove virtual in next commit.

{
var updatedRunSettingsXml = runsettingsXml;

var property = this.testHostManager.GetType().GetRuntimeProperties().FirstOrDefault(p => string.Equals(p.Name, oldTestHostPropertyName, StringComparison.OrdinalIgnoreCase));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay to run this for all test host managers?

Copy link
Contributor Author

@Faizan2304 Faizan2304 Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have to. There is no way to know dotnetTesthostManager.


} while (runSettingsNavigator.MoveToNext());

// Delele all invalid RunConfiguration Settings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Delele/Delete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

var listOfInValidRunConfigurationSettings = new List<string>();

// These are the list of valid RunConfiguration setting name which old testhost understand.
var listOfValidRunConfigurationSettings = new HashSet<string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a constant set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

{
if(!listOfValidRunConfigurationSettings.Contains(runSettingsNavigator.LocalName))
{
listOfInValidRunConfigurationSettings.Add(runSettingsNavigator.LocalName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove the node here directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its because when we delete a node, navigator jumps to parent and we lost track of last visited child.

@@ -121,11 +122,13 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH
isDebug: (testRunCriteria.TestHostLauncher != null && testRunCriteria.TestHostLauncher.IsDebug),
testCaseFilter: testRunCriteria.TestCaseFilter);

// This is workaround for the bug https://github.com/Microsoft/vstest/issues/970
var runsettings = this.RemoveNodesFromRunsettingsIfRequired(testRunCriteria.TestRunSettings);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need unit and integration tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added acceptance test for this.

@@ -87,6 +87,11 @@ public void Initialize(IEnumerable<string> pathToAdditionalExtensions)

this.activeTestRun.RunTests();
}
catch(Exception e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need unit tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :). Added in next commit.

[TestMethod]
public void StartTestRunShouldAbortTheRunIfAnyExceptionComesForTheProvidedTests()
{
var testExecutionContext = new TestExecutionContext(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove DRY violation and make this an instance variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

var mockTestRunEventsHandler = new Mock<ITestRunEventsHandler>();

// Call StartTestRun with faulty runsettings so that it will throw exception
this.executionManager.StartTestRun(new Dictionary<string, IEnumerable<string>>(), @"<RunSettings><RunConfiguration><TestSessionTimeout>0</TestSessionTimeout></RunConfiguration></RunSettings>", testExecutionContext, null, mockTestRunEventsHandler.Object);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StartTestRunWithTests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

/// </summary>
/// <param name="runsettingsXml">runsettings string</param>
/// <returns>runsetting after removing unrequired nodes</returns>
protected string RemoveNodesFromRunsettingsIfRequired(string runsettingsXml, ITestRunEventsHandler eventHandler)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemoveNodesFromRunsettingsIfRequired(string runsettingsXml, Action<TestMessageLevel, string> logMessage)

Refactor in ProxyExecutionManager to provide this function. Exception handling in PEM can use the same function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@Faizan2304 Faizan2304 merged commit 5dc8ff1 into microsoft:master Aug 4, 2017
@Faizan2304 Faizan2304 deleted the issue970 branch August 4, 2017 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants