Skip to content

Port last changes from Unit Test Adapater to master.#1614

Closed
paulvanbrenk wants to merge 8 commits intomicrosoft:masterfrom
paulvanbrenk:unittestfixes
Closed

Port last changes from Unit Test Adapater to master.#1614
paulvanbrenk wants to merge 8 commits intomicrosoft:masterfrom
paulvanbrenk:unittestfixes

Conversation

@paulvanbrenk
Copy link
Copy Markdown
Contributor

Ports the changes from #1605 to master

Copy link
Copy Markdown
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

The hashcode to string conversion seems wrong.


internal class NodejsProjectSettings
{
public NodejsProjectSettings()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can delete the ctor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And below.

stdout = string.Empty;
stderr = string.Empty;
}
public string title { get; set; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Public members should have PascalCase names.

public string workingFolder { get; set; }
public string projectFolder { get; set; }

public string framework { get; set; } = string.Empty;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will result in double assignment.

ulong hash = FnvOffsetBias;
do
{
bytesRead = stream.Read(buffer, 0, 4096);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

buffer.length

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, this is Vlad's code, so it's probably tuned. nvm

}

public string FullyQualifiedName
private string GetHash(string filePath)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

static

catch (IOException)
{
return ModulePath + "::" + TestName + "::" + TestFramework;
return "FILE_NOT_FOUND";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can these values be null?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like they can't.

using (var stream = File.OpenRead(filePath))
{
var hash = Hash.GetFnvHashCode(stream);
return Encoding.UTF8.GetString(hash);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does this do with invalid characters?

# Conflicts:
#	Nodejs/Product/TestAdapter/RunFromContextFileExtensions.cs
#	Nodejs/Product/TestAdapter/TestExecutor.cs
#	Nodejs/Product/TestAdapter/TestFrameworks/NodejsTestInfo.cs
Paul van Brenk added 4 commits November 1, 2017 16:35
# 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
@paulvanbrenk
Copy link
Copy Markdown
Contributor Author

@amcasey can you take another look

<Version>0.2.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

var hash = GetHash(modulePath);

this.ModulePath = modulePath;
this.ModuleName = $"{moduleName}[{hash}]";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do we need to uniquely identify this instance of the file by hashing its contents?

Copy link
Copy Markdown
Contributor

@ozyx ozyx Nov 3, 2017

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@paulvanbrenk paulvanbrenk Nov 7, 2017

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 ).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a much faster algorithm, since it has none of the crypto-requirements. (And widely used by Roslyn, and the TypeScript LS).

Copy link
Copy Markdown
Member

@billti billti Nov 3, 2017

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we already had GetRelativeFilePath? Sweet!

@paulvanbrenk
Copy link
Copy Markdown
Contributor Author

Combining this with other unit test work

@paulvanbrenk paulvanbrenk deleted the unittestfixes branch March 26, 2018 23:54
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.

7 participants