Moodle
  1. Moodle
  2. MDL-36807

Unit test enrol_database_testcase::test_sync_user_enrolments fails in MySQL when using a DB socket

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4, 2.5
    • Fix Version/s: 2.4.1
    • Component/s: Enrolments, Unit tests
    • Labels:
    • Environment:
      * Debian GNU/Linux
      * MySQL
      * Moodle using the DB socket connection
    • Database:
      MySQL
    • Testing Instructions:
      1. setup a Moodle site on MySQL using the DB socket connection option
      2. attempt to run the affected unit test: enrol_database_testcase enrol/database/tests/sync_test.php
      3. the test should complete correctly
    • Workaround:
      Hide

      I managed to get the test to run correctly after changing the value that the Moodle installer set in config.php from:

      • $CFG->dboptions = array (
          'dbpersist' => 0,
          'dbsocket' => 1
        );

        to:

      • $CFG->dboptions = array (
          'dbpersist' => 0,
          'dbsocket' => '/run/mysqld/mysqld.sock'
        );

      Show
      I managed to get the test to run correctly after changing the value that the Moodle installer set in config.php from: $CFG->dboptions = array ( 'dbpersist' => 0, 'dbsocket' => 1 ); to: $CFG->dboptions = array ( 'dbpersist' => 0, 'dbsocket' => '/run/mysqld/mysqld.sock' );
    • Affected Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_24_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      w51_MDL-36807_m25_mysocket

      Description

      When running the unit tests on a 2.4 site configured to use a DB socket connection to a MySQL database, enrol_database_testcase::test_sync_user_enrolments test fails while attempting to connect to the DB.

      • $ vendor/bin/phpunit enrol_database_testcase enrol/database/tests/sync_test.php
        PHPUnit 3.7.9 by Sebastian Bergmann.
         
        Configuration read from /home/jfilip/code/moodle24/phpunit.xml
         
        ESS
         
        Time: 1 second, Memory: 63.75Mb
         
        There was 1 error:
         
        1) enrol_database_testcase::test_sync_user_enrolments
        mysqli_real_connect(): (HY000/2002): No such file or directory
         
        /home/jfilip/code/moodle24/lib/adodb/drivers/adodb-mysqli.inc.php:113
        /home/jfilip/code/moodle24/lib/adodb/adodb.inc.php:555
        /home/jfilip/code/moodle24/lib/adodb/adodb.inc.php:4354
        /home/jfilip/code/moodle24/enrol/database/lib.php:856
        /home/jfilip/code/moodle24/enrol/database/lib.php:146
        /home/jfilip/code/moodle24/enrol/database/tests/sync_test.php:224
        /home/jfilip/code/moodle24/lib/phpunit/classes/advanced_testcase.php:76
         
        To re-run:
         vendor/bin/phpunit enrol_database_testcase enrol/database/tests/sync_test.php
         
        FAILURES!
        Tests: 1, Assertions: 3, Errors: 1, Skipped: 2.

      If I change the Moodle config.php file to specify the path to the MySQL socket file, rather than the standard boolean value of 1, the test works:

      • $ vendor/bin/phpunit enrol_database_testcase enrol/database/tests/sync_test.php
        PHPUnit 3.7.9 by Sebastian Bergmann.
         
        Configuration read from /home/jfilip/code/moodle24/phpunit.xml
         
        ...
         
        Time: 5 seconds, Memory: 67.25Mb
         
        OK (3 tests, 280 assertions)

      The same result happened regardless of whether I was running my system-installed phpunit binary or the one installed via composer.

        Gliffy Diagrams

          Activity

          Hide
          Justin Filip added a comment -

          I'm not sure if there is a way to fix this in the Moodle code? I've come across this problem running any unit test involving the DB with the socket option on my OSX machine. I always have to specify the socket path in that option there.

          If this is an issue that can't be fixed in code we should probably update the PHPUnit docs to indicate this configuration change needed to get that test to run correctly?

          Show
          Justin Filip added a comment - I'm not sure if there is a way to fix this in the Moodle code? I've come across this problem running any unit test involving the DB with the socket option on my OSX machine. I always have to specify the socket path in that option there. If this is an issue that can't be fixed in code we should probably update the PHPUnit docs to indicate this configuration change needed to get that test to run correctly?
          Hide
          Petr Skoda added a comment - - edited

          Hello, I have tried to copy the socket logic from our standard mysqli driver, it might help in some situations.

          Similar problem might be reported if you use 'localhost' instead of '127.0.0.1' on some servers.

          Thanks for the report.

          Show
          Petr Skoda added a comment - - edited Hello, I have tried to copy the socket logic from our standard mysqli driver, it might help in some situations. Similar problem might be reported if you use 'localhost' instead of '127.0.0.1' on some servers. Thanks for the report.
          Hide
          Justin Filip added a comment -

          This fixes the problem I was having.

          Thanks!

          Show
          Justin Filip added a comment - This fixes the problem I was having. Thanks!
          Hide
          Dan Poltawski added a comment -

          Added integration_held, as it looks like this is a master only change.

          Show
          Dan Poltawski added a comment - Added integration_held, as it looks like this is a master only change.
          Hide
          Justin Filip added a comment -

          This bug does affect 2.4. Is it not going to be fixed there as well?

          Show
          Justin Filip added a comment - This bug does affect 2.4. Is it not going to be fixed there as well?
          Hide
          Petr Skoda added a comment -

          I would not call it a bug, but here is stable backport anyway. Thanks.

          Show
          Petr Skoda added a comment - I would not call it a bug, but here is stable backport anyway. Thanks.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Integrated (24 & master), thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Integrated (24 & master), thanks!
          Hide
          Eloy Lafuente (stronk7) added a comment -

          OK (3 tests, 280 assertions)

          (although I was not getting any error before and I was using it already, plus my host is "localhost", so it's forced-used).

          Passing, anyway. Would be great if you confirm it's running also there, Justin.

          Show
          Eloy Lafuente (stronk7) added a comment - OK (3 tests, 280 assertions) (although I was not getting any error before and I was using it already, plus my host is "localhost", so it's forced-used). Passing, anyway. Would be great if you confirm it's running also there, Justin.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          And your fantastic code has met core, hope they become good friends for a long period.

          Closing, thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - And your fantastic code has met core, hope they become good friends for a long period. Closing, thanks!
          Hide
          Justin Filip added a comment -

          Hi Eloy, it's working correctly on 2.4.1 over here now with 'dbsocket' set to 1 on MySQL.

          Show
          Justin Filip added a comment - Hi Eloy, it's working correctly on 2.4.1 over here now with 'dbsocket' set to 1 on MySQL.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Perfect, thanks Justin!

          Show
          Eloy Lafuente (stronk7) added a comment - Perfect, thanks Justin!

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: