Skip to content

test(menu): add performance tests for mat-menu #20151

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

Merged
merged 4 commits into from
Aug 12, 2020

Conversation

wagnermaciel
Copy link
Contributor

No description provided.

@wagnermaciel wagnermaciel requested a review from a team as a code owner July 31, 2020 21:35
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 31, 2020
selector: 'app-root',
template: `
<button mat-button [matMenuTriggerFor]="menu">Menu</button>
<mat-menu #menu="matMenu">
Copy link
Member

Choose a reason for hiding this comment

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

We support multi-level menus too. Should we have a test that captures it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I ran into a bit of an issue with this. The main things I wanted to test out for nested menus is 1. is there any slowdown with opening the root menu if there are a couple of nested menus, and 2. how long it takes to open a menu fully.

The problem (which I left a comment for) is that calling getHarness seems to be an expensive operation which makes figuring out how expensive opening up submenus are.

I am wondering if I should change the test from opening a nested menu fully to just opening a single nested menu like

setup: () => open root menu and call getHarness for the sub menu
prepare: () => close sub menu
work: () => open on sub menu

@crisbeto Lmk what are your thoughts

Copy link
Member

Choose a reason for hiding this comment

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

Harnesses trigger change detection and wait for it to finish before every action so I'm not sure whether we should be basing our performance tests on them. @mmalerba do you think that we should use Protractor directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using protractor has it's own issues with cdk-overlay-container

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the harnesses explicitly run change detection in e2e tests (though I'm sure they cause it by clicking). I think using the harness to open/close pretty much boils down to the same thing you would be doing via protractor directly anyways. The part where the harnesses might add some overhead is in searching for submenus, e.g. await loader.getHarness(MatMenuHarness.with({ triggerText: 'Sub Menu 1' })) - it would be ideal if we could pause measuring while doing this and then resume again when we go to actually click it, kind of like a "setup" step but it runs in the middle of the test. Not sure if that's possible though

Copy link
Member

Choose a reason for hiding this comment

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

Don't they also wait for animations for finish? @wagnermaciel it might be worth trying to import the NoopAnimationsModule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was under the impression that we actually wanted to wait for animations to finish

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think I figured out the correct solution here. The MatMenuHarness uses .sendKeys(Key.ESCAPE) to close it's menu. It does not call click on the .cdk-overlay-backdrop like I was trying to do. This avoids the issue I was running into while trying to use protractor for these tests, so no need to use harnesses here anymore.

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Aug 4, 2020
@andrewseguin andrewseguin merged commit 9b0cd3c into angular:master Aug 12, 2020
andrewseguin pushed a commit that referenced this pull request Aug 12, 2020
* test(menu): add performance tests for mat-menu

* fixup! test(menu): add performance tests for mat-menu

* fixup! test(menu): add performance tests for mat-menu

* fixup! test(menu): add performance tests for mat-menu

(cherry picked from commit 9b0cd3c)
@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 Sep 12, 2020
@wagnermaciel wagnermaciel deleted the menu-benchmark branch January 14, 2021 19:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants