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

core_search internal state can be persisted between unit tests

XMLWordPrintable

      The search subsystem maintains a static variable, $coursedeleting to track what courses are being deleted throughout the lifetime of a request. See core_search\manager::course_deleting_start and core_search\manager::course_deleting_finish

      The method core_search\manager::context_deleted makes use of this variable to skip deleting contexts in situations where the whole course would be deleted anyway.

      In normal circumstances, this is fine, even if course_deleting_finish never gets called, because the $coursedeleting variable only lives for the duration of the request. However, in PHPUnit tests, it can cause problems.

      MDL-74993 introduced a test that deliberately sets up a situation where the delete_course function will throw an exception. This results in the situation where course_deleting_start is called, and course_deleting_finish is not. Meaning that for all later tests being run, the $coursedeleting variable is set.

      This can result in the simpledb tests failing; because when it tests context deletion, sometimes the $coursedeleting variable prevents the context from being deleted (as the code assumes a course deletion will remove it).

      To replicate (you may need to run this twice to get the situation where a course ID gets reused in multiple tests):

      vendor/bin/phpunit --stop-on-failure --testsuite=core_testsuite,search_simpledb_testsuite --filter "modinfolib|simpledb"
      

      This situation is quite unfortunate, it requires deep knowledge of the internals of both the core_search subsystem and Moodle's PHPUnit setup to figure out what's going on. And it would be easy for any future search plugins to experience the same sort of failure seen here.

        1. 400.png
          400.png
          632 kB
        2. 401.png
          401.png
          465 kB
        3. master.png
          master.png
          475 kB

            cameron1729 cameron1729
            cameron1729 cameron1729
            Dmitrii Metelkin Dmitrii Metelkin
            Andrew Lyons Andrew Lyons
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 24 minutes
                1h 24m

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