Slow PHPunit (6 hours to run entire test suite!)

Slow PHPunit (6 hours to run entire test suite!)

by Rex Lorenzo -
Number of replies: 4
How long are the entire PHPunit test running for everyone else? In the docs it says:
"A typical run of full PHPUnit tests for Moodle 2.7 takes 10-20 minutes"

But for me on the current master (2019112900.00) the entire PHPunit test suite is taking 6 hours to run, and that's after I tried some optimizations.

The machine is a Optiplex 5070 Micro Form Factor.

  • Intel Core i5-9500t (6 Cores/9MB/6T/up to 3.7GHz/35W)
  • 12GB RAM
  • 256GB Solid State Drive
  • Ubuntu 18.04
  • MySQL 5.5.x (latest version available to Ubuntu)
    • utf8mb4_bin collation
  • PHP 7.2.x (latest version available to Ubuntu)

The optimizations I did were:

Those two settings reduced the runtime from 9 hours to  6 hours, but I am nowhere close to 20-30 minutes. The machine I am running on is not the fastest machine, but it is new and I thought would be decent enough with 6 cores and running an SSD. Do I need a beefier machine?

Any more advice on how to improve performance? I am running a local LAMP server with Jenkins running the tests.

The command I am using to run the PHPunit tests is:

vendor/bin/phpunit --log-junit 'reports/unitreport.xml' --coverage-clover 'reports/clover.xml'


Average of ratings: Useful (1)
In reply to Rex Lorenzo

Re: Slow PHPunit (6 hours to run entire test suite!)

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
It takes 20-30 minutes for me. I do have some optimisations but only the ones I use for dev.


My vet is that you’re using xdebug. Don’t. It really does make everything slow.

You want coverage..? Use `phpdbg -qrr vendor/bin/phpunit` instead.

Average of ratings: Useful (2)
In reply to Andrew Lyons

Re: Slow PHPunit (6 hours to run entire test suite!)

by Rex Lorenzo -

Wow.. you are right. I disabled xdebug and now the tests finish in 1 hour. I will try Postgres or MariaDB.

However, when I tried the following command for code coverage I get the an error:

phpdbg -qrr vendor/bin/phpunit --log-junit reports/unitreport.xml --coverage-clover reports/clover.xml

[PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 65536 bytes) in /var/lib/jenkins/workspace/moodle-core-phpunit/lib/classes/component.php on line 752][0m
[1;31m[PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 65536 bytes) in /var/lib/jenkins/workspace/moodle-core-phpunit/lib/testing/classes/test_lock.php on line 94][0m

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 65536 bytes) in /var/lib/jenkins/workspace/moodle-core-phpunit/lib/classes/component.php on line 752

Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 65536 bytes) in /var/lib/jenkins/workspace/moodle-core-phpunit/lib/testing/classes/test_lock.php on line 94
But with the code coverage command removed and without phpdbg I do not get that error.. So I will have to live without code coverage for now.


In reply to Rex Lorenzo

Re: Slow PHPunit (6 hours to run entire test suite!)

by Renaat Debleu -
Picture of Core developers Picture of Plugin developers

It is normal that you run into problems when you want to generate a coverage report for your complete Moodle site and all installed plugins.

Better check the code coverage of each plugin:

phpdbg -qrr vendor/bin/phpunit --log-junit reports/unitreport1.xml --coverage-clover reports/clover1.xml --configuration mod/forum
phpdbg -qrr vendor/bin/phpunit --log-junit reports/unitreport2.xml --coverage-clover reports/clover2.xml --configuration mod/url
...
In reply to Rex Lorenzo

Re: Slow PHPunit (6 hours to run entire test suite!)

by Davo Smith -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

In my experience, Postgres runs unit tests vastly faster than MySQL (but I've not done any comparisons for a while, so the difference may be less now). Running with code coverage is also going to slow things down a lot.