-
Bug
-
Resolution: Fixed
-
Minor
-
3.11.1, 4.0
-
MOODLE_311_STABLE, MOODLE_400_STABLE
-
MOODLE_310_STABLE, MOODLE_311_STABLE
-
master-
MDL-72239-v2 -
Hi,
I have a failing core test:
root@013d65e07b28:/siteroot# vendor/bin/phpunit --testsuite='core_course_testsuite' --filter='test_course_get_enrolled_courses_for_logged_in_user' |
Moodle 3.11.1 (Build: 20210712), 0e295ea322b7fe8d37c364e9c26128fcf316d718 |
Php: 7.4.3, pgsql: 10.15 (Debian 10.15-1.pgdg90+1), OS: Linux 5.4.0-77-generic x86_64 |
PHPUnit 9.5.4 by Sebastian Bergmann and contributors. |
|
.FFFFFFFF 9 / 9 (100%) |
|
Time: 00:05.884, Memory: 92.50 MB |
|
There were 8 failures: |
|
1) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "less than query limit" (3, 2, 0, 0, 2, array('testcourse0', 'testcourse1')) |
Failed asserting that 1 matches expected 2. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
2) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "more than query limit" (3, 7, 0, 0, 4, array('testcourse0', 'testcourse1', 'testcourse2', 'testcourse3', 'testcourse4', 'testcourse5', 'testcourse6')) |
Failed asserting that 3 matches expected 4. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
3) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "limit less than query limit" (3, 7, 2, 0, 2, array('testcourse0', 'testcourse1')) |
Failed asserting that 1 matches expected 2. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
4) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "limit less than query limit with offset" (3, 7, 2, 2, 2, array('testcourse2', 'testcourse3')) |
Failed asserting that 1 matches expected 2. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
5) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "limit less than total" (3, 9, 6, 0, 3, array('testcourse0', 'testcourse1', 'testcourse2', 'testcourse3', 'testcourse4', 'testcourse5')) |
Failed asserting that 2 matches expected 3. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
6) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "less results than limit" (4, 9, 20, 0, 4, array('testcourse0', 'testcourse1', 'testcourse2', 'testcourse3', 'testcourse4', 'testcourse5', 'testcourse6', 'testcourse7', 'testcourse8')) |
Failed asserting that 3 matches expected 4. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
7) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "less results than limit exact divisible" (3, 9, 20, 0, 5, array('testcourse0', 'testcourse1', 'testcourse2', 'testcourse3', 'testcourse4', 'testcourse5', 'testcourse6', 'testcourse7', 'testcourse8')) |
Failed asserting that 4 matches expected 5. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
8) core_course_courselib_testcase::test_course_get_enrolled_courses_for_logged_in_user with data set "less results than limit with offset" (3, 9, 10, 5, 3, array('testcourse5', 'testcourse6', 'testcourse7', 'testcourse8')) |
Failed asserting that 2 matches expected 3. |
|
/siteroot/course/tests/courselib_test.php:4679 |
/siteroot/lib/phpunit/classes/advanced_testcase.php:80 |
|
FAILURES!
|
Tests: 9, Assertions: 18, Failures: 8. |
|
It fails on asserting that $expecteddbqueries is equal to $DB->perf_get_queries() - $initialquerycount). In fact there are less db queries than expected.
I turned out that a plugin that I have installed has an observer, that listens to user_enrolment_created events and then calls get_complete_user_data() which does a query to mdl_user_lastaccess table, so its columns get cached. Thus, when the test does moodle_database->get_columns() it gets columns for mdl_user_lastaccess from the cache. As a result, the test does less db calls than expected.
Steps to triage the issue:
- Install a helper plaugin https://github.com/golenkovm/moodle-local_mdl_helper
- Checkout to
MDL-72239branch - Run unit tests:
vendor/bin/phpunit --testsuite='core_course_testsuite' --filter='test_course_get_enrolled_courses_for_logged_in_user'