Reduce memory usage with Symfony and the PHPUnit bridge

Starting with Symfony 2.7, Symfony PHPUnit Bridge was created as a great way to get wear alerts from your tests (see the related Symfony blog post ). As part of this package, garbage collection has also been disabled, which seems to make a memory footprint from a large set of test suites out of control.

For example, without a bridge:

Time: 5.01 minutes, Memory: 964.75Mb OK, but incomplete, skipped, or risky tests! Tests: 1189, Assertions: 2380, Incomplete: 2. 

And the same test suite with the bridge turned on:

 Time: 4.98 minutes, Memory: 3003.00Mb OK, but incomplete, skipped, or risky tests! Tests: 1189, Assertions: 2380, Incomplete: 2. Remaining deprecation notices (9) 

The documentation notes that removing garbage collection during testing is designed to reduce the occurrence of segmentation errors under certain conditions, which we have not yet experienced.

I understand that we could simply re-enable garbage collection in our application-specific PHPUnit boot file, or we could also remove the bridge from the autoloader and manually register only the obsolescence handler. However, I'm more interested in the intent associated with this inclusion (and, in truth, perhaps all that is missing is the documentation on how to avoid this behavior).

Also, is there a related change that we must make so that we structure our tests to deal with this? This is a test suite that includes many functional tests with a full stack and much more. It seems that running without garbage collection can break many large test suites if I haven't missed something.

This is under PHP 5.5.9, PHPUnit 4.7.7 and Symfony 2.7.3.

+5
source share
1 answer

The code that includes garbage collection also mentions a PHP error that it forbade . No final code exists in order to easily and reliably display the error by itself, and it is not clear whether later versions (in the 5.6 series and esp 7.0 series) will be immune to this problem.

Turning gc can also speed up the speed of the run - for the same reasons as with Composer - garbage collection can take a considerable amount of time.

Re-enabling it in the startup script after disabling it on the bridge can help with memory.

I would be more likely to find out why your tests take up so much memory - seeing how much memory is used before and after the tests, and clearing the objects used in the tearDown() functions can do a lot to clear the memory.

+2
source

All Articles