-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Data providers retention eases memory leaks #3715
Comments
@nesk Goodmorning and thanks for the detailed use case you presented re: resource usage of dataproviders. I have been doing some work on this already on the PHPUnit side, which indeed does save (quite a lot) of memory and improves performance. However that work is still experimental and targetted to version 8. Is your project and test suite open to the public? I'd be great if you could hit me up per email or on LinkedIn as this is my current area of research. |
Unfortunately, no, my project is not open to the public. However, maybe I could try to create a showcase to help you see what's really happening? |
Hello again @nesk!
That'd be great, I've poked you on LinkedIn so we can discuss this outside the Github issues. |
Here's the showcase: https://gist.github.com/nesk/343d78c13eee91355e999877d3518eb6 Clone the repo, install the dependencies, then run phpunit: git clone https://gist.github.com/343d78c13eee91355e999877d3518eb6.git showcase
cd showcase
composer install
php -d memory_limit=128M ./vendor/bin/phpunit The command should fail with the following error:
To avoid the memory limit error, use: php -d memory_limit=256M ./vendor/bin/phpunit |
@nesk thank you! I will have a look tonight. |
Superseded by #3736 |
I have some routes to test functionally, to achieve this I have a test which depends on a data provider. This data provider contains datasets with, for each, a URL and some URL parameters to fill.
Since those URL parameters generally accept an ID to fetch an entity inside the database, I did something like this to ease the writing of my tests (I'm not writing all the required code, so we can focus on what's important):
This code works well, the entities are persisted and the URLs are properly generated. However, with my real codebase, I have 80 datasets in my provider with multiple entities (not just one like in the example).
The memory consumption is fine once PHPUnit generates all the data to estimate the number of tests to run, but, once the tests start running, the memory consumption quickly explodes because the entities are being persisted by Doctrine, which makes them use more memory. Since PHPUnit keeps all the data generated by providers in memory, those heavy entities (and probably many other things created by Doctrine) stay in memory.
I do understand why PHPUnit works that way, it needs to keep the data in memory to be able to display it if a test fails. However, maybe we could have an option to disable this data cache, avoiding to much memory consumption? Or maybe I shouldn't write my tests like this?
The text was updated successfully, but these errors were encountered: