-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Very slow tests since vesion 12.2.0 #1452
Comments
Hi @lousley , might I ask you to share a test which demonstrates the degradation? |
Also, to confirm - 12.5.0 also has the issue, right? |
yes i have the problem also with version 12.5. interestingly i just saw that if i have a testfile without ngmocks imports or functionalities but i have many imports and providers it becomes extremely slow. defineTouches and geneateTouches is probably the problem even if no ng-mocks is needed in the corresponding file? |
is there any way to turn off/override this generatetouches? |
Hi there, thanks for the info and support. might you also downgrade looks like another change in A13 will cause huge refactoring, so I could try to find the issue which impacts performance degradation and to fix it there too. |
Regarding Considering that a simple test takes 6.5 seconds on your side, I would say that your app looks heavy and can have a lot of declarations, and that's why I'll try to find a way to add metrics so we could debug where |
sounds like a good plan on the metrics. As a guideline we will try to avoid MockModule, we are supposed to be shallow testing anyway 🤷 . But the atomic option is to appealing. Is there a separate issue logged for jest performance improvements ? |
In my case i have the following TestBed I think the problem is the AwbTestingModule with many declarations / imports / exports and providers as: If I remove the TestingModule and use only the required declarations / imports / providers in the corresponding test file, then the test is already much faster. I also see that in this testfile no ng-mocks stuff is needed at all, nevertheless it is very slow. |
assuming you mean : ng-mocks 12.1.2 with ng13. If that is the case the tests will not run:
I can downgrade to 12.4.0 only. I re-ran the same test on both versions below. The 30+ seconds with
|
I can also confirm that. We are using Angular 12 + ng-mocks 12.1.0 and any version above 12.1.0 is extremely slowing down tests. |
Hey @gagle, might you provide how much time it needed for the test above? |
@satanTime: i would also like to share my time difference: Version 12.1.2: 277.31s This based on 5500 tests |
thanks for the numbers, ill try to figure out how to optimise that. |
any updates? :S |
Hi, not much, jest doesn't want to merge the fix which would simplify the flow. And I haven't had time yet to dig deeper and to find alternative solutions. Also, feel free to post any findings here. For example, if you see that some functions cause the issue and others aren't. It would really help once I'm on fixing it. |
I cannot get our tests to even start after updating to angular 13 and ng-mocks v13. I start the unit tests with I tried downgrading to ng-mocks 12.5 but that doesn't seem compatible with ang13. Getting "declaration has been passed into ng-mocks without Angular decorators. " errors. In our ang12 version and ng-mocks 12.2 all worked fine. |
Hi @rbirkgit, Thanks for the info. Looks like there is a recursion. |
Unfortunately it's a big project with many dependencies and don't think we can share the code. The strange thing is, removing all references to ng-mocks all is fine (just to get a base line). Then all I do is adding one place with MockComponent(xxx) and boom, it hangs using v13. Not sure if there are some ways to get more debug info or how to test what could cause the issue? |
All I do is add this in one of our tests and the whole thing hangs before even the first test starts. No other use of ng-mocks anywhere.
|
Yep, I think some root installs don't work well. could you check for example not I'll prepare a special debug version which should shed light on the source of the issue, would it be possible for you to run it and share with me its output? |
I would be happy to test and run debug versions and share results. |
Played more today and my latest conclusion is that it's not actually hanging, it really really slow. We have a 60s timeout where it will disconnect the test and that what I am experiencing. And the browser then just sits there. So we have a shared MockModule where we have mocked the most common services etc we use. Then I went ahead and deleted every spec file we have except one, which is a bare minimum. Just test that component is created. Now I added a dummy empty component and added MockComponent(MyTestComponent) to this minimal test. Still hangs, or rather timeouts ater 60sec. So started removing mocks in our mock module and after removing enough of them, the app.component test passed taking 25s. It usually is much faster, much less than 1sec. When we add the MockComponent things explode exponentially. |
Do you mean 25s without ng-mocks? Or without it it's 1s? |
The test takes 0.3sec normally. The moment I add a single line mocking a dummy empty component, it takes 25.4sec
|
This is my code in my test:
I had to delete mocks in our MockModule one by one until the test got under the 60sec timeout. Not sure why code in our MockModule should affect anything when adding the |
we had the same problem, but since we upgraded to angular 13.2.4, this problem is no longer so extreme. What version are you running and what does your test.ts file look like? |
Aha. One question. In test.ts, where it has initTestEnvironment, do you have BrowserDynamicTestingModule or a different one? Also it would be nice to see all dependencies in your project from package.json. |
We are using Angular 13.3.0 test.ts is the default one:
|
Hi @rbirkgit, could give me a favor and test the next conditions: preconditions: you have one spec file which needs 25 secs to be run. Now, please check how much time is needed to execute the test. it('test', () => {
expect(1).toEqual(1);
}); Please check how much time it needs. after that, please add the same Please check how much time it needs. At the end, you should have 3 numbers:
|
I did the first step as you described. I removed all spec files except one simple one with one it that only tests for component creation (default test). This runs in less than a second. Added the line you described above the describe:
Now tests disconnects after 60s (timeout). Without the ngMocks line, again it's less than a second. |
Thanks. I think I know where the issue is now. Not an easy fix, but I'll try my best. |
And to confirm: MockModule is super fat, isn't it? |
Yes, our MockModule is fat. I started removing code from it and it got faster, but still very slow. Removed enough, I got it to 25sec. Removed most, 15sec. We also have what may or may not be a separate issue that after the test, it still hangs. Meaning it says the it() passed but testing is still sitting there not exiting. Removing ng-mocks, it exits right away. I know this is not much to go on but thought I try to describe. Our tests could be optimized with mocking things more properly. Right now it's not mocking a component's every dependent service and some are running during the tests, which using other services, along with observables etc. That where we wanted to cleanup the tests with ng-mocks. It was very promising and worked great in the ang12 env. Thanks for looking into it. Would be awesome if we can continue using it. It's a very nice tool. |
Thanks for the feedback. I'll keep you all posted. |
Hi @rbirkgit, not sure if it helps, nevertheless, could you try one of those things: |
Tested both options. No difference. |
I was able to reproduce the issue. Working on a fix. |
Hi all, could you verify that this build solves the issue? Also, please delete |
I will try when I get back to my computer later today. Thanks!! |
Tested it. Success!! It's as fast as v12 now and works! I need to pinch myself and try again :) |
Awesome!!! Thanks for confirming. I'll release it tomorrow. |
Now all tests run and normal speed. Got 6 tests failing of 350 in this project. Need to figure out next if it's a new issue or we did something wrong that now got exposed. Four them has
This was working before. I'm not sure yet if it's an ang13 update issue, or a new ngMocks problem or our code just bad. But thought I post here just in case. Will look at it more on Monday. |
Why do you not want to use MockBuilder? It resolves the hell of dependencies. Anyway, if there is a bug, please create a new issue. |
HI @satanTime i can confirm that the performance is back as before. thanks for the fix. really nice! |
v13.3.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems. |
Hello together
Since we updated ng-mocks to version 12.2.0 on our project (Angular 12 with unittests jasmine / karma), we are seeing extreme performance issues. Do you have any spontaneous idea what this could be?
I did some debugging and saw that defineTouches / generateTouches fills the touches SET with extremely many entries.
We only use in some tests ngMocks and MockComponent.
Thanks for any feedback.
The text was updated successfully, but these errors were encountered: