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

Better detect equivalence in our strong name provider #74151

Merged
merged 5 commits into from
Jun 28, 2024

Conversation

ToddGrun
Copy link
Contributor

Addresses #74058

LiveUnitTest team reported a fairly recent regression where Roslyn started reporting Project changed workspace events during file addition / removal. This causes the LUT window to unnecessarilly rerun tests.

This regressed as part of a change I made back in March around passing in a temp path to the compiler's strong name provider, as otherwise an EmitStream call fails, breaking intellisense in projects using assembly signing. (Change here: #72587)

The regression is due to me changing several callers to creating a strong name provider based on the path, instead of them all using the default instance. With the previous behavior, equality checks on these newly created StrongNameFileSystem and DesktopStrongNameProvider instances would return false, even though the temp path in the file systems were the same.

It's a bit of a windy path to how this relates to the LUT window. The Roslyn ProjectSystemProject.ChangeProjectProperty call is the crux of where the issue was being exposed. UpdateProjectOptions_NoLock was calling it with a new DesktopStrongNameProvider created with the temp path as outlined above. ChangeProjectProperty checks the old value of the strong name provider against the newValue, and if they are the same, it doesn't add anything to the batched events it will later send out. However, in this case, the equality check failed, so we started sending out a project changed notification, breaking the LUT behavior.

The fix here is to simply implement Equals in StrongNameFileSystem, and have DesktopStrongNameProvider use that instead of just checking for reference equality.

Addresses dotnet#74058

LiveUnitTest team reported a fairly recent regression where Roslyn started reporting Project changed workspace events during file addition / removal. This causes the LUT window to unnecessarilly rerun tests.

This regressed as part of a change I made back in March around passing in a temp path to the compiler's strong name provider, as otherwise an EmitStream call fails, breaking intellisense in projects using assembly signing. (Change here: dotnet#72587)

The regression is due to me changing several callers to creating a strong name provider based on the path, instead of them all using the default instance. With the previous behavior, equality checks on these newly created StrongNameFileSystem and DesktopStrongNameProvider instances would return false, even though the temp path in the file systems were the same.

It's a bit of a windy path to how this relates to the LUT window. The Roslyn ProjectSystemProject.ChangeProjectProperty call is the crux of where the issue was being exposed. UpdateProjectOptions_NoLock was calling it with a new DesktopStrongNameProvider created with the temp path as outlined above. ChangeProjectProperty checks the old value of the strong name provider against the newValue, and if they are the same, it doesn't add anything to the batched events it will later send out. However, in this case, the equality check failed, so we started sending out a project changed notification, breaking the LUT behavior.

The fix here is to simply implement Equals in StrongNameFileSystem, and have DesktopStrongNameProvider use that instead of just checking for reference equality.
@ToddGrun ToddGrun requested a review from a team as a code owner June 25, 2024 18:10
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 25, 2024
@ToddGrun
Copy link
Contributor Author

Adding @333fred and @jaredpar as they have a little bit of context with the PR in which I broke this: #72587

@ToddGrun ToddGrun requested review from jaredpar and 333fred June 25, 2024 18:14
@ToddGrun ToddGrun linked an issue Jun 25, 2024 that may be closed by this pull request
Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Should we also add a test at the workspaces layer so we don't regress something like this again?

var provider2 = new DesktopStrongNameProvider(keyFileSearchPaths: [@"c:\test2"]);

Assert.NotEqual(provider1, provider2);
}
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to add one more test for case sensitivity also counting as unequal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

}

var other = (StrongNameFileSystem)obj;
return string.Equals(_signingTempPath, other._signingTempPath, StringComparison.Ordinal);
Copy link
Member

Choose a reason for hiding this comment

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

interesting that this is ordinal. I guess that's ok as if the casing changes we will update in that case (which would be rare anyways). It doesn't hurt to make a new provider outside of perf. might be work stating this.

ToddGrun and others added 3 commits June 25, 2024 16:39
Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com>
Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com>
Add test for case sensitivity
@ToddGrun
Copy link
Contributor Author

Should we also add a test at the workspaces layer so we don't regress something like this again?

Is there an existing test class that this would fit well into? I took a quick look earlier, and didn't see any somewhat easy way to test this change at that level.

@ToddGrun
Copy link
Contributor Author

@333fred and @jaredpar for the compiler reviews

@ToddGrun ToddGrun merged commit a1d7eb9 into dotnet:main Jun 28, 2024
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 28, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProjectChanged Events Triggered More Often
6 participants