Skip to content

Conversation

jayaranigarg
Copy link
Member

@jayaranigarg jayaranigarg commented Apr 19, 2018

Scenario which was broken -
If suppose TestProject has a config file having assembly binding redirect of System.Runtime to 4.1. Our TestAdapter which has a dependency of System.Runtime of 4.0, uses the above config file and tries to load System.Runtime 4.1. Since assembly resolver was not set at the time of loading of adapter, it is unable to find 4.1 version of assembly and bombs.

Fix - Adding resolution paths at the time of creation of appdomains.

Validations-

  1. 2 Projects having different adapter versions works fine with enable and Appdomain
  2. Above scenario.

@jayaranigarg jayaranigarg changed the title Re-fix Compatibility issue of resetting appbase Adding Resolution Paths during appdomain creation (Compatibility Isuue) Apr 19, 2018
public void SetupHost()
{
if (this.AppDomainCreationDisabledInRunSettings())
List<string> resolutionPaths = this.GetResolutionPaths(this.sourceFileName, VSInstallationUtilities.IsCurrentProcessRunningInPortableMode());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add test for ResolutionPaths being set.

}

this.targetFrameworkVersion = this.GetTargetFrameworkVersionString(this.sourceFileName);
// Adding extensions folder to resolution paths
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this is runner location(OM assembly location).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

List<string> resolutionPaths = this.GetResolutionPaths(this.sourceFileName, VSInstallationUtilities.IsCurrentProcessRunningInPortableMode());

// Check if user specified any runsettings
MSTestAdapterSettings adapterSettings = MSTestSettingsProvider.Settings;
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the declaration near to usage.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

// Check if user specified any runsettings
MSTestAdapterSettings adapterSettings = MSTestSettingsProvider.Settings;

if (resolutionPaths != null && resolutionPaths.Count > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be happen. Even if it is empty or null, We should add below two paths.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

}
catch (Exception exception)
{
if (EqtTrace.IsErrorEnabled)
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 if check for error scenarios.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why so?

{
if (EqtTrace.IsErrorEnabled)
{
EqtTrace.Error(exception);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Add more details while logging the exception. At line 190 too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

var configFile = this.GetConfigFileForTestSource(this.sourceFileName);
AppDomainUtilities.SetConfigurationFile(appDomainSetup, configFile);

this.domain = this.appDomain.CreateDomain("TestSourceHost: Enumering assembly", null, appDomainSetup);
Copy link
Contributor

Choose a reason for hiding this comment

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

Change the name of appdomain to sourcefilename.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


// Case when Child-appdomain was created successfully, update appbase and set assembly resolver on it
else if (this.domain != null)
if (this.domain != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to inverted if IsAppDomainCreationDisable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


// Log error when child-appdomain was expected to be created but wasn't created.
else
else if (!this.AppDomainCreationDisabledInRunSettings())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not required. Are DisableAppDomain settings from runsettings only once.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

try
{
var additionalSearchDirectories =
adapterSettings.GetDirectoryListWithRecursiveProperty(this.domain.SetupInformation.ApplicationBase);
Copy link
Contributor

Choose a reason for hiding this comment

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

this.domain.SetupInformation.ApplicationBase value should be testsource directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

Reuse additionalSearchDirectories.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

try
{
this.parentDomainAssemblyResolver = new AssemblyResolver(resolutionPaths);
this.parentDomainAssemblyResolver.AddSearchDirectoriesFromRunSetting(adapterSettings.GetDirectoryListWithRecursiveProperty(null));
Copy link
Contributor

Choose a reason for hiding this comment

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

GetDirectoryListWithRecursiveProperty should take test source directory.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DoNotParallelizeTestProject", "test\E2ETests\TestAssets\DoNotParallelizeTestProject\DoNotParallelizeTestProject.csproj", "{8080DE48-CFD9-4F33-908A-8B71108CA223}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompatTestProject", "test\E2ETests\TestAssets\CompatTestProject\CompatTestProject.csproj", "{2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompatTestProject", "test\E2ETests\TestAssets\CompatTestProject\CompatTestProject.csproj", "{2D2C5B73-F1F1-47C8-BC5C-A172E9BB3D16}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider having separate sln for test assets.

this.SetContext(sourceFileName);
}

public AppDomain AppDomain
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it internal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

{
List<string> resolutionPaths = this.GetResolutionPaths(this.sourceFileName, VSInstallationUtilities.IsCurrentProcessRunningInPortableMode());

EqtTrace.Info("DesktopTestSourceHost.SetupHost(): Creating assembly resolver with resolution paths {0}.", string.Join(",", resolutionPaths.ToArray()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Check if tracing enabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


if (adapterSettings != null)
{
try
Copy link
Contributor

Choose a reason for hiding this comment

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

DRY.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

var mockRunSettings = new Mock<IRunSettings>();
mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);

StringReader stringReader = new StringReader(runSettingxml);
Copy link
Contributor

Choose a reason for hiding this comment

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

DRY.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>$(TestFxRoot)artifacts\TestAssets\ComponentTests</OutputPath>
<SignAssembly>true</SignAssembly>
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this if not required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Required. SampleFrameworkExtensions also has it. PlatformServices.Desktop.Component.Tests throws strong name error if key.snk is not referenced in TestProjectForAssemblyResolution.

@jayaranigarg
Copy link
Member Author

@dotnet-bot Test Windows / Debug Build please

@jayaranigarg jayaranigarg merged commit 45f5af0 into microsoft:master May 8, 2018
@jayaranigarg
Copy link
Member Author

Fixes #384 and #356

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.

3 participants