5

I have a 32GB machine and running over 2000 test cases using phpdbg for code coverage.

phpdbg -qrr -d memory_limit=-1./vendor/phpunit/phpunit/phpunit --debug --verbose

After running for some time, it throws the following error even memory_limit is -1

map() failed: [12] Cannot allocate memory [ PHP Fatal error: Out of memory (allocated 5830606848) (tried to allocate 65536 bytes) ]

Suneel Kumar
  • 1,650
  • 2
  • 21
  • 31
vivek
  • 151
  • 1
  • 6
  • 1
    what are you running that would take up 5GB of memory!!!! – cmorrissey Sep 01 '17 at 13:39
  • there are around 2000 test cases. I am running them for code coverage. If i run them without code coverage just using phpunit, it take 4GB of memory – vivek Sep 01 '17 at 14:08

1 Answers1

1

You are likely leaking memory and not getting it cleaned up. There are plugins that will report how much memory each test uses, and others that will try to automatically clean up - though with the update to PHPunit v6+, some may need attention to work with the namespace testcase classes.

One that tries to free-up memory is 'mybuilder/phpunit-accelerator', but if you can find particularly memory-heavy test classes, you can manually null-out the variables being used in a teardown() function.

Making sure that you are only collecting coverage data for your own code (src/, and maybe tests/) will also save a huge amount of memory (and time) - but whitelist the 'src/' directory and don't try to blacklist/exclude 'vendor/'.

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110
  • Thanks.. Will try and update the thread. But is there a max limit on the php process? Why is it getting killed after 5GB even when the machine has 32 GB. Even when running without code coverage, the execution takes up 4 GB of memory. – vivek Sep 02 '17 at 18:57
  • Hey Alister, Can you share the plugin which generates memory for each UT. I tried but not able to find one. – vivek Sep 02 '17 at 19:31
  • 2
    Memory is leaking at createApplicaiton @ Illuminate\Foundation\Testing\TestCase. It adds 2 MB for each test case. it seems to be a problem with phpunit with no solution available. – vivek Sep 04 '17 at 06:53