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

Static variable $cache in grade_get_setting causes unit test failures

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Run Unit Tests

      1. Replicate the issue by a failing unit test that should not fail
        Apply 0001-MDL-70245-test-patch.patch  (Please find the attached for this)
        git am 0001-MDL-70245-test-patch.patch
      2. Run vendor/bin/phpunit lib/tests/upgradelib_test.php
        Test failed
        core_upgradelib_testcase::test_upgrade_update_category_grademax_regrade_final_grades
        Failed asserting that '10.00000' matches expected 20.
      3. Apply the solution in this tracker. There could be merge conflict since we included the same unit test in the solution
      4. Run same test vendor/bin/phpunit lib/tests/upgradelib_test.php

      Expected:

              The failing unit test passed

      Show
      Run Unit Tests Replicate the issue by a failing unit test that should not fail Apply 0001- MDL-70245 -test-patch.patch  (Please find the attached for this) git am 0001- MDL-70245 -test-patch.patch Run vendor/bin/phpunit lib/tests/upgradelib_test.php Test failed core_upgradelib_testcase::test_upgrade_update_category_grademax_regrade_final_grades Failed asserting that '10.00000' matches expected 20. Apply the solution in this tracker. There could be merge conflict since we included the same unit test in the solution Run same test vendor/bin/phpunit lib/tests/upgradelib_test.php Expected:         The failing unit test passed
    • Affected Branches:
      MOODLE_310_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_310_STABLE, MOODLE_39_STABLE
    • Pull 3.9 Branch:
      MDL-70245-MOODLE_39_STABLE
    • Pull 3.10 Branch:
      MDL-70245-MOODLE_310_STABLE
    • Pull Master Branch:
      MDL-70245-master

      Description

      When the unit test tries to validate "finalgrade" with different set of grade max, then it will fail after "test_upgrade_calculated_grade_items_freeze" function in core_testsuite because the static $cache variable does not reset and the "minmaxtouse" collides with previous unit tests.

       

      Steps to reproduce:

      1. Write unit test (attached in MDL-70245-patch.txt) that implement to validate "finalgrade" with different set of grademax (for course category and grade item) after the function "test_upgrade_calculated_grade_items_freeze" .
      2. Run vendor/bin/phpunit --testsuite=core_testsuite

       

      Expected:

      Unit tests pass

       

      Actual:

      Unit tests fail with unexpected "finalgrade" getting returned (because it is using the previous "minmaxtouse" which is set in the function "test_upgrade_calculated_grade_items_freeze")

       

       

        Attachments

        1. 0001-MDL-70245-test-patch.patch
          3 kB
          John Yao
        2. MDL-70245-patch.txt
          5 kB
          Anupama Dharmajan

          Activity

            People

            Assignee:
            tomotsuyuki Tomo Tsuyuki
            Reporter:
            anupamadharmajan Anupama Dharmajan
            Peer reviewer:
            John Yao John Yao
            Integrator:
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Tester:
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Andrew Lyons, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              18/Jan/21

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 45 minutes
                45m