Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-78156

PHPUnit error with test_get_user_groups_with_visibility

XMLWordPrintable

    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_402_STABLE
    • Hide
      1. Init PHPUnit with Oracle database. php admin/tool/phpunit/cli/init.php
      2. Run a few repetitions of this test. vendor/bin/phpunit --filter test_get_user_groups_with_visibility
      3. Verify that it's consistently passing and the failure in the description of the issue doesn't happen any more.
      Show
      Init PHPUnit with Oracle database. php admin/tool/phpunit/cli/init.php Run a few repetitions of this test. vendor/bin/phpunit --filter test_get_user_groups_with_visibility Verify that it's consistently passing and the failure in the description of the issue doesn't happen any more.

      This seems to be a "random" error introduced by the tests added @ MDL-68093.

      Specially noticeable with Oracle, but any database can be affected potentially, we are getting these here and there:

      Link:

      1) core\grouplib_test::test_get_user_groups_with_visibility
      Failed asserting that two arrays are equal.
      --- Expected
      +++ Actual
      @@ @@
       Array (
      -    0 => '1'
      -    1 => '2'
      -    2 => '3'
      -    3 => '4'
      +    0 => 3
      +    1 => 4
      +    2 => 1
      +    3 => 2
       )
       
      /var/www/html/lib/tests/grouplib_test.php:2124
      /var/www/html/lib/phpunit/classes/advanced_testcase.php:94
      

      It's clearly the typical problem of order not being guaranteed by groups_get_user_groups().

      And there are two possible approaches to fix it:

      1. If it's ok to force an ordering to happen, do it (ORDER by id or whatever) in the core function.
      2. If really the order doesn't matter, then "relax" the test by using assertEqualsCanonicalizing, so only values are tested, irrespectively of the position.

      Normally, 90% of times we just follow approach #1, guaranteeing the function returns ordered stuff.

      But #2 is also ok if we aren't going to need any specific order ever.

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Ilya Tregubov Ilya Tregubov
            Andrew Lyons Andrew Lyons
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 30 minutes
                2h 30m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.