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

Resolve testhost from source directory if we couldnt resolve it via nuget cache #690

Merged
merged 2 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -394,14 +394,12 @@ private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath,
}
}

if (string.IsNullOrEmpty(testHostPath))
{
// Try resolving testhost from output directory of test project. This is required if user has published the test project
// and is running tests in an isolated machine. A second scenario is self test: test platform unit tests take a project
// dependency on testhost (instead of nuget dependency), this drops testhost to output path.
testHostPath = Path.Combine(sourceDirectory, "testhost.dll");
EqtTrace.Verbose("DotnetTestHostManager: Assume published test project, with test host path = {0}.", testHostPath);
}
// If we are here it means it couldnt resolve testhost.dll from nuget chache.
// Try resolving testhost from output directory of test project. This is required if user has published the test project
// and is running tests in an isolated machine. A second scenario is self test: test platform unit tests take a project
// dependency on testhost (instead of nuget dependency), this drops testhost to output path.
testHostPath = Path.Combine(sourceDirectory, "testhost.dll");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should handle case if testhost.dll does not exist in sourceDirectory too for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. Would this publish the Extensions folder, that has the default extensions here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AbhitejJohn : very interesting catch 👍 . we are planning to handle thing related to Extension in separate task.

EqtTrace.Verbose("DotnetTestHostManager: Assume published test project, with test host path = {0}.", testHostPath);

return testHostPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,73 @@ public void GetTestHostProcessStartInfoShouldIncludeTestHostPathFromDepsFile()
Assert.IsTrue(startInfo.Arguments.Contains(testHostFullPath));
}

[TestMethod]
public void GetTestHostProcessStartInfoShouldIncludeTestHostPathFromSourceDirectoryIfNugetpathDoesntExist()
{
// Absolute path to the source directory
var sourcePath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "test.dll");

string runtimeConfigFileContent =
@"{
""runtimeOptions"": {
""additionalProbingPaths"": [
""C:\\packages""
]
}
}";

string depsFileContent =
@"{
""runtimeTarget"": {
""name"": "".NETCoreApp,Version=v1.0"",
""signature"": ""8f25843f8e35a3e80ef4ae98b95117ea5c468b3f""
},
""compilationOptions"": {},
""targets"": {
"".NETCoreApp,Version=v1.0"": {
""microsoft.testplatform.testhost/15.0.0-Dev"": {
""dependencies"": {
""Microsoft.TestPlatform.ObjectModel"": ""15.0.0-Dev"",
""Newtonsoft.Json"": ""9.0.1""
},
""runtime"": {
""lib/netstandard1.5/Microsoft.TestPlatform.CommunicationUtilities.dll"": { },
""lib/netstandard1.5/Microsoft.TestPlatform.CrossPlatEngine.dll"": { },
""lib/netstandard1.5/Microsoft.VisualStudio.TestPlatform.Common.dll"": { },
""lib/netstandard1.5/testhost.dll"": { }
}
}
}
},
""libraries"": {
""microsoft.testplatform.testhost/15.0.0-Dev"": {
""type"": ""package"",
""serviceable"": true,
""sha512"": ""sha512-enO8sZmjbhXOfiZ6hV2ncaknaHnQbrGVsHUJzzu2Dmoh4fHFro4BF1Y4+sb4LOQhu4b3DFYPRj1ncd1RQK6HmQ=="",
""path"": ""microsoft.testplatform.testhost/15.0.0-Dev"",
""hashPath"": ""microsoft.testplatform.testhost.15.0.0-Dev""
}
}
}";

MemoryStream runtimeConfigStream = new MemoryStream(Encoding.UTF8.GetBytes(runtimeConfigFileContent));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use using...

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 use using here as these memory stream are getting use in mock

this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.runtimeconfig.dev.json", FileMode.Open, FileAccess.ReadWrite)).Returns(runtimeConfigStream);
this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.runtimeconfig.dev.json")).Returns(true);

MemoryStream depsFileStream = new MemoryStream(Encoding.UTF8.GetBytes(depsFileContent));
this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.deps.json", FileMode.Open, FileAccess.ReadWrite)).Returns(depsFileStream);
this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.deps.json")).Returns(true);

string testHostFullPath = @"C:\packages\microsoft.testplatform.testhost/15.0.0-Dev\lib/netstandard1.5/testhost.dll";
this.mockFileHelper.Setup(ph => ph.Exists(testHostFullPath)).Returns(false);

string testHostPath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "testhost.dll");
Copy link
Contributor

Choose a reason for hiding this comment

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

string testHostPath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "testhost.dll"); [](start = 12, length = 88)

Reuse class variable declared above:
Line No : 63 : this.defaultTestHostPath = @"\tmp\testhost.dll";


var startInfo = this.dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, this.defaultConnectionInfo);

Assert.IsTrue(startInfo.Arguments.Contains(testHostPath));
}

[TestMethod]
public async Task DotNetCoreErrorMessageShouldBeReadAsynchronouslyAsync()
{
Expand Down