Skip to content

destroy testing modules during resetTestingModule #38336

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

Closed

Conversation

josephperrott
Copy link
Member

@josephperrott josephperrott commented Aug 3, 2020

See individual commits.

Fixes #18831

@josephperrott josephperrott added area: testing Issues related to Angular testing features, such as TestBed action: review The PR is still awaiting reviews from at least one requested reviewer area: router area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Aug 3, 2020
@ngbot ngbot bot modified the milestone: needsTriage Aug 3, 2020
@muhammedMoussa
Copy link

Hi, can (this.subscription && !this.subscription.closed) shorthanded
to be (!this.subscription?.closed)

@josephperrott josephperrott force-pushed the shared-styles-cleanup branch 5 times, most recently from d7d142b to b803904 Compare August 6, 2020 20:40
@josephperrott josephperrott force-pushed the shared-styles-cleanup branch from b803904 to 1490c1d Compare August 10, 2020 22:15
@josephperrott josephperrott force-pushed the shared-styles-cleanup branch 4 times, most recently from 63e25ad to 7c48418 Compare August 21, 2020 20:08
cexbrayat added a commit to cexbrayat/angular that referenced this pull request Nov 27, 2020
There is currently a known issue with the framework when testing that leaks style.
See angular#31834

A possible temporary workaround is to manually call the service that adds/aremoves the style.
See angular#31834 (comment)

This workaround will be unnecessary when angular#38336 lands.

This speeds up the `ng test` task locally by ~30%:
- before: Executed 649 of 652 (skipped 3) SUCCESS (24.161 secs / 20.072 secs)
- after: Executed 649 of 652 (skipped 3) SUCCESS (17.854 secs / 15.584 secs)
@cexbrayat cexbrayat mentioned this pull request Nov 27, 2020
14 tasks
cexbrayat added a commit to cexbrayat/angular that referenced this pull request Nov 29, 2020
There is currently a known issue with the framework when testing that leaks style.
See angular#31834

A possible temporary workaround is to manually call the service that adds/aremoves the style.
See angular#31834 (comment)

This workaround will be unnecessary when angular#38336 lands.

This speeds up the `ng test` task locally by ~30%:
- before: Executed 649 of 652 (skipped 3) SUCCESS (24.161 secs / 20.072 secs)
- after: Executed 649 of 652 (skipped 3) SUCCESS (17.854 secs / 15.584 secs)
Copy link
Contributor

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

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

It looks like CircleCI is requiring this PR be rebased:

        CircleCI config on master has been modified since commit 250e299,
        which this PR is based on.

        Please rebase the PR on master after fetching from upstream.

        Rebase instructions for PR Author, please run the following commands:

          git fetch upstream master;
          git checkout shared-styles-cleanup;
          git rebase upstream/master;
          git push --force-with-lease;

schema: DomElementSchemaRegistry, private component: RendererType2) {
super(eventManager, document, ngZone, schema);
console.log('renderer created');
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this just for debugging? Can it be removed now?

@ngbot ngbot bot modified the milestones: needsTriage, Backlog Mar 11, 2021
@elesueur
Copy link

@AndrewKushnir can you describe how this change is breaking?

@AndrewKushnir
Copy link
Contributor

@elesueur given that there was no cleanup of shared styles, tests might be written in a way where they depend on the presence of some CSS rules added during previous tests. With the proposed cleanup, such tests will start to fail (so this is a breaking change). We've confirmed that by running tests in Google's codebase. Before merging this change it's important to estimate potential risks and come up with proper rollout plan/communication.

@josephperrott please correct me if I'm wrong or if I'm missing something.

@josephperrott
Copy link
Member Author

That is correct, I would only add that it could go even further and maintain the state in other ways between tests. Since modules are not torn down, things like the state of a service can leak between tests.

@elesueur
Copy link

That is correct, I would only add that it could go even further and maintain the state in other ways between tests. Since modules are not torn down, things like the state of a service can leak between tests.

As a maintainer of several large Angular apps, I would want to learn about which tests are relying on pollution (and fix them) and get the performance improvement rather than wait for a 'less breaky' solution that hides the pollution and leaves me with slow tests :)

…ule`

Previously, the reference to the test `NgModuleRef` was set to null when the testing module
was reset via `resetTestingModule`.  While this clears the reference to the specific instance
of `NgModuleRef`, it does not properly break down/destroy the established injectibles within
the `TestBed`.  By calling `destroy` on the `_moduleRef` instance, the entire established
structue is correctly torn down to truly reset what the module has created.
@josephperrott josephperrott force-pushed the shared-styles-cleanup branch from 0ce8927 to 2505cf2 Compare May 14, 2021 17:40
@crisbeto
Copy link
Member

Will be superseded by #42566.

@josephperrott
Copy link
Member Author

Closing in favor of #42566

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 18, 2021
@josephperrott josephperrott deleted the shared-styles-cleanup branch August 31, 2023 17:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime area: router area: testing Issues related to Angular testing features, such as TestBed breaking changes cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Destroy listeners aren't called in TestBed
7 participants