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

fix(core): error in TestBed if module is reset mid-compilation in ViewEngine #42669

Closed
wants to merge 2 commits into from

Conversation

Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
@crisbeto
Copy link
Member

@crisbeto crisbeto commented Jun 26, 2021

When TestBed.compileComponents is called under ViewEngine, we kick off a compilation and return a promise that resolves once the compilation is done. In most cases the consumer doesn't have to await the returned promise, unless their components have external resources.

The problem is that the test could be over by the time the promise has resolved, in which case we still cache the factory of the test module. This becomes a problem if another compilation is triggered right afterwards, because it'll see that we still have a _moduleFactory and it won't recreate the factory.

These changes resolve the issue by saving a reference to the module type that is being compiled and checking against it when the promise resolves.

Note that even though this problem was discovered while trying to roll out the new test module teardown behavior in the Components repo (angular/components#23070), it has been there for a long time. The new test behavior made it more apparent.

@google-cla google-cla bot added the cla: yes label Jun 26, 2021
@crisbeto crisbeto marked this pull request as ready for review Jun 26, 2021
@pullapprove pullapprove bot requested a review from AndrewKushnir Jun 26, 2021
@ngbot ngbot bot added this to the Backlog milestone Jun 26, 2021
@ngbot ngbot bot added this to the Backlog milestone Jun 26, 2021
@ngbot ngbot bot added this to the Backlog milestone Jun 26, 2021
@ngbot ngbot bot added this to the Backlog milestone Jun 26, 2021
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

LGTM 🍪

Loading

@ngbot

This comment was marked as off-topic.

alxhub
alxhub approved these changes Jun 29, 2021
packages/core/testing/src/test_bed.ts Show resolved Hide resolved
Loading
Copy link
Member

@IgorMinar IgorMinar left a comment

Whoa! What a temporal bug. Thanks for fixing this. I left a suggestion to make the test more robust.

Loading

packages/core/test/test_bed_spec.ts Outdated Show resolved Hide resolved
Loading
crisbeto added 2 commits Jun 30, 2021
…wEngine

When `TestBed.compileComponents` is called under ViewEngine, we kick off a compilation and return a promise that resolves once the compilation is done. In most cases the consumer doesn't _have_ to await the returned promise, unless their components have external resources.

The problem is that the test could be over by the time the promise has resolved, in which case we still cache the factory of the test module. This becomes a problem if another compilation is triggered right afterwards, because it'll see that we still have a `_moduleFactory` and it won't recreate the factory.

These changes resolve the issue by saving a reference to the module type that is being compiled and checking against it when the promise resolves.

Note that while this problem was discovered while trying to roll out the new test module teardown behavior in the Components repo (angular/components#23070), it has been there for a long time. The new test behavior made it more apparent.
@crisbeto crisbeto force-pushed the test-bed-teardown-error branch from 8379c04 to f2fc9f4 Jun 30, 2021
@jessicajaniuk jessicajaniuk removed the request for review from AndrewKushnir Jun 30, 2021
jessicajaniuk added a commit that referenced this issue Jun 30, 2021
…wEngine (#42669)

When `TestBed.compileComponents` is called under ViewEngine, we kick off a compilation and return a promise that resolves once the compilation is done. In most cases the consumer doesn't _have_ to await the returned promise, unless their components have external resources.

The problem is that the test could be over by the time the promise has resolved, in which case we still cache the factory of the test module. This becomes a problem if another compilation is triggered right afterwards, because it'll see that we still have a `_moduleFactory` and it won't recreate the factory.

These changes resolve the issue by saving a reference to the module type that is being compiled and checking against it when the promise resolves.

Note that while this problem was discovered while trying to roll out the new test module teardown behavior in the Components repo (angular/components#23070), it has been there for a long time. The new test behavior made it more apparent.

PR Close #42669
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Jul 31, 2021

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.

Loading

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.