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

Avoid duplication in package assembly list #10550

Merged
merged 2 commits into from
Apr 8, 2020

Conversation

mmisol
Copy link
Collaborator

@mmisol mmisol commented Apr 7, 2020

Purpose

Fixes the issue described here https://forum.dynamobim.com/t/package-contents-listed-twice-in-the-package-manager/48994. Tracked as DYN-2602.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.

Reviewers

@aparajit-pratap @QilongTang

FYIs

@mjkkirschner

@mmisol mmisol added the DNM Do not merge. For PRs. label Apr 7, 2020
var assemblies = packageList
.SelectMany(p => p.LoadedAssemblies.Where(y => y.IsNodeLibrary))
.Select(a => a.Assembly)
.ToList();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are basically two things that were fixed:

  1. The call to EnumerateAssembliesInBinDirectory was replaced by using LoadedAssemblies. This avoids re-adding assemblies to LoadedAssemblies.
  2. The assemblies list is materialized. Before these changes, the call to EnumerateAssembliesInBinDirectory was made each time the enumerable was enumerated, which happened once per event handler for PackageLoaded. That caused triplication of the libraries for me on latest master.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mmisol you mentioned that EnumerateAssembliesInBinDirectory was being called in a couple of other places. Do those need to be replaced with LoadedAssmeblies as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right. What I was seeing in the stack trace was actually this line of code being executed when the enumeration was materialized. This happened in two event handlers of OnPackagesLoaded, one in DynamoModel.cs(978) and another in EngineController.cs(521).

Copy link
Contributor

Choose a reason for hiding this comment

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

@mmisol So I assume whichever event handler called second time, with this fix, we will no longer re-adding assemblies to LoadedAssemblies. Do we want to create a test by mocking up the situation and check the end LoadedAssemblies?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that was part of the issue. The call to TryLoadPackageIntoLibrary is the first to call EnumerateAssembliesInBinDirectory and after this LoadedAssemblies should be used to read them.

I'll see to add a test. I have to think about what needs to be mocked, hopefully it's not too difficult.

@aparajit-pratap
Copy link
Contributor

aparajit-pratap commented Apr 7, 2020

@mmisol could you create a JIRA issue for this for tracking purposes.

@aparajit-pratap
Copy link
Contributor

@mmisol thanks for fixing this issue so quickly! Are there any tests you can add for this?

@mjkkirschner
Copy link
Member

mjkkirschner commented Apr 7, 2020

should the use of this enumerateAssemblies method also be changed here:

LocalPackages.SelectMany(x => x.EnumerateAssembliesInBinDirectory().Where(y => y.IsNodeLibrary));
(what Aparajit asked above)

@mmisol
Copy link
Collaborator Author

mmisol commented Apr 7, 2020

@mjkkirschner That code seems to have the same problem. I'll check if it's being used somewhere.

@mmisol mmisol changed the title [WIP] Avoid duplication in package assembly list Avoid duplication in package assembly list Apr 7, 2020
@mmisol mmisol removed the DNM Do not merge. For PRs. label Apr 7, 2020
@mmisol
Copy link
Collaborator Author

mmisol commented Apr 7, 2020

Added a test. This is ready for review @aparajit-pratap @QilongTang

@mjkkirschner About the method you mentioned, it's obsoleted and there are no usages, so I left it alone. Let me know if you would like to change ti anyway, but testing it would be difficult.

@QilongTang
Copy link
Contributor

QilongTang commented Apr 7, 2020

@mmisol Thank you for adding the test. LGTM. Not sure if we need to include the other spot also part of this PR, I think it is OK to not include. Oops.. Wrong button

@QilongTang QilongTang closed this Apr 7, 2020
@QilongTang QilongTang reopened this Apr 7, 2020
@mmisol
Copy link
Collaborator Author

mmisol commented Apr 8, 2020

Re-thinking about what I wrote yesterday, unit testing the obsolete method should be easy. If you guys think it's safer to change it and unit test it rather than leaving as-is let me know and I can change it.

@aparajit-pratap
Copy link
Contributor

Re-thinking about what I wrote yesterday, unit testing the obsolete method should be easy. If you guys think it's safer to change it and unit test it rather than leaving as-is let me know and I can change it.

I think this is good. LGTM.

@mmisol
Copy link
Collaborator Author

mmisol commented Apr 8, 2020

Is this PR good to be merged @QilongTang @aparajit-pratap @mjkkirschner ? If so, can I get an approval? Thank you

@QilongTang QilongTang added the LGTM Looks good to me label Apr 8, 2020
@QilongTang
Copy link
Contributor

@mmisol Ship it!

@mmisol mmisol merged commit fc7c07b into DynamoDS:master Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM Looks good to me
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants