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

purge_all() on unit tests can fail as store::initialise is different from store::initialise_unit_test_instance

XMLWordPrintable

    • MOODLE_30_STABLE, MOODLE_31_STABLE, MOODLE_32_STABLE
    • MOODLE_32_STABLE
    • Hide

      Use APCu first to ensure the changes are correct.

      1. Install apcu

      brew install php70-apcu
      aptitude install php-apcu
      

      2. update your config.php

      define('TEST_CACHE_USING_APPLICATION_STORE' , 'apcu');
      

      This will run all unit tests against APCu.
      4. Run PHPUnit, ensure all tests pass.
      5. Edit your php config eg; /etc/php/7.0/conf.d/ext-apcu.ini and comment out all lines. This removes APCu support, but you still have APCu in your configuration.
      6. Run PHPUnit, all tests except 1 will pass, it will say cachestore_file was used, but cachestore_apcu was expected. (You can also do this with memcache, as seen in MDL-56347)
      8. update your config.php

      define('TEST_CACHE_USING_APPLICATION_STORE' , 'invalidplugin');
      

      9. Run PHPUnit, ensure all tests pass except 1, which will report that cachestore_file was used, but cachestore_invalidplugin was expected.
      10. Reset your configuration

      define('TEST_CACHE_USING_APPLICATION_STORE' , 'apcu');
      vi /etc/php/7.0/conf.d/ext-apcu.ini  #enabled the plugin again.
      

      10. To give your computer something to do overnight, Run the behat suite in this configuration to confirm that all behat testing passes. Or convince Rajesh to change the nightly to use APCu as the default backing store

      Now to confirm all stores have been changed correctly;

      Test instructions taken from MDL-45513 and need to be executed again to ensure it all works correctly.

      Common prep

      You need to do this before running the following suites.

      1. Install memcached on your server.
      2. Install mongodb on your server.
      3. Install the memcache php extension.
      4. install the memcached php extension.
      5. Install the mongodb php extension.
      6. Ensure memcached and mongo are running.
      7. Start a second memcached instance on another port. We'll need this for testing "sudo -u memcache /usr/bin/memcached -d -m 128 -p 11212 -u memcache -l 127.0.0.1"
      8. Edit your config.php and add the following:

        <?php
        define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://127.0.0.1:27017');
        define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211');
        define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11212');
        

      9. Run full unit tests and record time taken (all must pass). You'll refer to this in both tests.

      Test altcacheconfigpath

      1. Edit your config.php and set $CFG->altcacheconfigpath = '/tmp/';
      2. Browse to your site and configure a memcached store instance in the cache config screen (Settings > Plugins > Caching > Cache configuration)
      3. Map it as the default application cache
      4. Save your changes
      5. In your console run `sudo cp /tmp/cacheconfig.php /tmp/cacheconfig.php.bak`
      6. Run full unit tests again and wait for it to finish
      7. Ensure that everything passes
      8. Hopefully it is quicker
      9. Run `sdiff -s /tmp/cacheconfig.php /tmp/cacheconfig.php.bak | wc -l` and check it shows 0.
      10. In your browser inspect the cache configuration and check it hasn't changed.

      Test TEST_CACHE_USING_APPLICATION_STORE define.

      1. Make sure a memcached instance is running on your server.
      2. Edit your config.php and remove $CFG->altcacheconfigpath
      3. Add:

        define('TEST_CACHE_USING_APPLICATION_STORE', 'memcache');
        

      4. Run full unit tests again and wait for it to finish
      5. Ensure that everything passes
      6. Hopefully it is quicker than the very first run.
      Show
      Use APCu first to ensure the changes are correct. 1. Install apcu brew install php70-apcu aptitude install php-apcu 2. update your config.php define('TEST_CACHE_USING_APPLICATION_STORE' , 'apcu'); This will run all unit tests against APCu. 4. Run PHPUnit, ensure all tests pass. 5. Edit your php config eg; /etc/php/7.0/conf.d/ext-apcu.ini and comment out all lines. This removes APCu support, but you still have APCu in your configuration. 6. Run PHPUnit, all tests except 1 will pass, it will say cachestore_file was used, but cachestore_apcu was expected. (You can also do this with memcache, as seen in MDL-56347 ) 8. update your config.php define('TEST_CACHE_USING_APPLICATION_STORE' , 'invalidplugin'); 9. Run PHPUnit, ensure all tests pass except 1, which will report that cachestore_file was used, but cachestore_invalidplugin was expected. 10. Reset your configuration define('TEST_CACHE_USING_APPLICATION_STORE' , 'apcu'); vi /etc/php/7.0/conf.d/ext-apcu.ini #enabled the plugin again. 10. To give your computer something to do overnight, Run the behat suite in this configuration to confirm that all behat testing passes. Or convince Rajesh to change the nightly to use APCu as the default backing store Now to confirm all stores have been changed correctly; Test instructions taken from MDL-45513 and need to be executed again to ensure it all works correctly. Common prep You need to do this before running the following suites. Install memcached on your server. Install mongodb on your server. Install the memcache php extension. install the memcached php extension. Install the mongodb php extension. Ensure memcached and mongo are running. Start a second memcached instance on another port. We'll need this for testing "sudo -u memcache /usr/bin/memcached -d -m 128 -p 11212 -u memcache -l 127.0.0.1" Edit your config.php and add the following: <?php define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://127.0.0.1:27017'); define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211'); define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11212'); Run full unit tests and record time taken (all must pass). You'll refer to this in both tests. Test altcacheconfigpath Edit your config.php and set $CFG->altcacheconfigpath = '/tmp/'; Browse to your site and configure a memcached store instance in the cache config screen (Settings > Plugins > Caching > Cache configuration) Map it as the default application cache Save your changes In your console run `sudo cp /tmp/cacheconfig.php /tmp/cacheconfig.php.bak` Run full unit tests again and wait for it to finish Ensure that everything passes Hopefully it is quicker Run `sdiff -s /tmp/cacheconfig.php /tmp/cacheconfig.php.bak | wc -l` and check it shows 0. In your browser inspect the cache configuration and check it hasn't changed. Test TEST_CACHE_USING_APPLICATION_STORE define. Make sure a memcached instance is running on your server. Edit your config.php and remove $CFG->altcacheconfigpath Add: define('TEST_CACHE_USING_APPLICATION_STORE', 'memcache'); Run full unit tests again and wait for it to finish Ensure that everything passes Hopefully it is quicker than the very first run.

      When using TEST_CACHE_USING_APPLICATION_STORE that behaves correctly, then created caches aren't always cleared using purge_all() or the reset mechanism for PHPUnit.

      At the largest level, this is a global problem not just for PHPUnit. However it is also an inherit design flaw in the way cache_purge and store interation is designed for MUC at this time. In the scope of this issue it's not possible to address that. Issues like MDL-53875 and MDL-45584 are the beginning of discussion about these issues. They are big, require buy-in and code restructuring. Possibly deprecation and removal of certain cachestore types where it is not possible to implement the correct behaviour. So they are deemed out of scope for the resolution of this issue.

      The two key current drivers for this are the integration of Redis cachestore which can't use TEST_CACHE_USING_APPLICATION_STORE without these changes and also MDL-49149 which allows the uses of a static cache store to improve PHPUnit performance.

            mr-russ Russell Smith
            mr-russ Russell Smith
            Rajesh Taneja Rajesh Taneja
            Andrew Lyons Andrew Lyons
            Jun Pataleta Jun Pataleta
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

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