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

PHPUnit isolated tests reset too often

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 4.2.4, 4.3.1
    • 4.2.3, 4.3.1
    • Unit tests
    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-79637-403
    • MDL-79637-master
    • Hide
      1. Apply the supplied patch:

        # master:
        git am path/to/0001-master-79637.patch
        # 42/43:
        git am path/to/0001-42-43-79637.patch
        

      2. Intialise PHPUnit
      3. In a new console window run:

        rm /tmp/test.log
        touch /tmp/test.log
        tail -F /tmp/test.log
        

      4. Run PHPUnit on the relevant branch:

        ./vendor/bin/phpunit lib/tests/component_test.php
        

        1. Confirm that the first line is for vendor/bin/phpunit and PHPUNIT_ISOLATED_TEST is false
        2. Confirm that the subsequent lines are for "Standard input code" and PHPUNIT_ISOLATED_TEST is true
      Show
      Apply the supplied patch: # master: git am path/to/0001-master-79637.patch # 42/43: git am path/to/0001-42-43-79637.patch Intialise PHPUnit In a new console window run: rm /tmp/test.log touch /tmp/test.log tail -F /tmp/test.log Run PHPUnit on the relevant branch: ./vendor/bin/phpunit lib/tests/component_test.php Confirm that the first line is for vendor/bin/phpunit and PHPUNIT_ISOLATED_TEST is false Confirm that the subsequent lines are for " Standard input code " and PHPUNIT_ISOLATED_TEST is true

      Before we run any test we reset the database and ensure that state.

      We do this by keeping track of the number of times we've written to the database.

      When we run isolated tests we reset the database before we run the test, then we start the isolated run.
      The isolated run does not have access to the DB write counter, so it is initialised as null again. This means that we write before the test, then write again on the phpunit isolated run bootstrap.

      The database is again reset, if required, after the run completes.

      We need to adjust the bootstrap to not reset if it is an isolated run because we know that isolated runs can only be called from within PHPUnit, and we only do this after we have reset the database (if it needs it).

        1. 0001-42-43-79637.patch
          0.9 kB
        2. 0001-master-79637.patch
          0.9 kB
        3. MDL-79637.png
          MDL-79637.png
          326 kB

            dobedobedoh Andrew Lyons
            dobedobedoh Andrew Lyons
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Jun Pataleta Jun Pataleta
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            1 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 - 5 hours, 26 minutes
                5h 26m

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