Port last changes from Unit Test Adapater to master.#1614
Port last changes from Unit Test Adapater to master.#1614paulvanbrenk wants to merge 8 commits intomicrosoft:masterfrom
Conversation
amcasey
left a comment
There was a problem hiding this comment.
The hashcode to string conversion seems wrong.
|
|
||
| internal class NodejsProjectSettings | ||
| { | ||
| public NodejsProjectSettings() |
| stdout = string.Empty; | ||
| stderr = string.Empty; | ||
| } | ||
| public string title { get; set; } |
There was a problem hiding this comment.
Public members should have PascalCase names.
| public string workingFolder { get; set; } | ||
| public string projectFolder { get; set; } | ||
|
|
||
| public string framework { get; set; } = string.Empty; |
There was a problem hiding this comment.
This will result in double assignment.
| ulong hash = FnvOffsetBias; | ||
| do | ||
| { | ||
| bytesRead = stream.Read(buffer, 0, 4096); |
There was a problem hiding this comment.
Oh, this is Vlad's code, so it's probably tuned. nvm
| } | ||
|
|
||
| public string FullyQualifiedName | ||
| private string GetHash(string filePath) |
| catch (IOException) | ||
| { | ||
| return ModulePath + "::" + TestName + "::" + TestFramework; | ||
| return "FILE_NOT_FOUND"; |
There was a problem hiding this comment.
I would return null here and have the caller ?? it with the error message. Bonus points for using a localized error message.
| } | ||
| } | ||
|
|
||
| public string FullyQualifiedName => string.Join("::", this.ModuleName, this.TestName, this.TestFramework); |
| using (var stream = File.OpenRead(filePath)) | ||
| { | ||
| var hash = Hash.GetFnvHashCode(stream); | ||
| return Encoding.UTF8.GetString(hash); |
There was a problem hiding this comment.
What does this do with invalid characters?
# Conflicts: # Nodejs/Product/TestAdapter/RunFromContextFileExtensions.cs # Nodejs/Product/TestAdapter/TestExecutor.cs # Nodejs/Product/TestAdapter/TestFrameworks/NodejsTestInfo.cs
# Conflicts: # Common/Product/SharedProject/SolutionEventsListener.cs # Nodejs/Product/TestAdapter/TestAdapter.csproj # Nodejs/Product/TestAdapterImpl/RunFromContextFileExtensions.cs # Nodejs/Product/TestAdapterImpl/TestExecutor.cs
# Conflicts: # Common/Product/SharedProject/SolutionEventsListener.cs
|
@amcasey can you take another look |
| <Version>0.2.0</Version> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
| <ItemGroup /> |
| var hash = GetHash(modulePath); | ||
|
|
||
| this.ModulePath = modulePath; | ||
| this.ModuleName = $"{moduleName}[{hash}]"; |
There was a problem hiding this comment.
We do we need to uniquely identify this instance of the file by hashing its contents?
There was a problem hiding this comment.
Hi Bill. I'd like to comment on this since I was the one who originally implemented this. On TFS 2015 / 2017, there is a feature which shows how long a certain test has been failing ("Failing since" on a test run). Since the path to the file was part of the unique identifier, the same test running on two machines with different drive names (for example) were seen as two different tests, thus making this metric inaccurate. The fix is to generate a hash based on file contents so the same test running on different machines, regardless of location, will be recognized as such in TFS. I'd be open to a more elegant fix for this issue, if there is one. Let me know if you have any other questions. Cheers
There was a problem hiding this comment.
Would the path relative to the project root solve this? (e.g. https://social.msdn.microsoft.com/Forums/vstudio/en-US/954346c8-cbe8-448c-80d0-d3fc27796e9c/how-to-convert-absolute-file-path-to-relative-path-in-c?forum=csharpgeneral )
There was a problem hiding this comment.
I changed this to instead of using a Hash now creates a new based on the relative path.
|
|
||
| namespace Microsoft.NodejsTools.TestAdapter.TestFrameworks | ||
| { | ||
| internal static class Hash |
There was a problem hiding this comment.
Why implement our own hashing algorithm rather than use one in the .NET Framework (e.g. https://msdn.microsoft.com/en-us/library/xa627k19(v=vs.110).aspx ).
There was a problem hiding this comment.
This is a much faster algorithm, since it has none of the crypto-requirements. (And widely used by Roslyn, and the TypeScript LS).
There was a problem hiding this comment.
If SHA1/256 is fast enough for Git to check if an entire repo has any changes, then I'm sure its quick enough to go over a few test files. That said, never mind... it's not a major issue. (And I'd rather use the relative path anyway... which will be way faster again 😉 )
Instead of hashing the contents use the (sanitized) project relative path to uniquely identify the test case.
| public NodejsTestInfo(string modulePath, string testName, string testFramework, int line, int column) | ||
| public NodejsTestInfo(string modulePath, string testName, string testFramework, int line, int column, string projectRootDir) | ||
| { | ||
| var relativePath = CommonUtils.GetRelativeFilePath(projectRootDir, modulePath); |
There was a problem hiding this comment.
So we already had GetRelativeFilePath? Sweet!
|
Combining this with other unit test work |
Ports the changes from #1605 to master