MDL-45699 cache: acceptance test improvements
We now use the unit test cache config class when running acceptance tests so that the same defines are applicable there.
This commit is contained in:
Vendored
+11
-11
@@ -236,36 +236,36 @@ The second method is a lot more intensive for the system. There are defined inva
|
||||
When you invalidate by event the cache API finds all of the definitions that subscribe to the event, it then loads the stores for each of those definitions and purges the keys from each store.
|
||||
This is obviously a recursive, and therefore, intense process.
|
||||
|
||||
### Unit tests
|
||||
Both the cache API and the cache stores have unit tests.
|
||||
Please be aware that several of the cache stores require configuration in order to be able operate in the unit tests.
|
||||
Tests for stores requiring configuration that havn't been configured will be skipped.
|
||||
### Testing
|
||||
Both the cache API and the cache stores have tests.
|
||||
Please be aware that several of the cache stores require configuration in order to be able operate in the tests.
|
||||
Tests for stores requiring configuration that haven't been configured will be skipped.
|
||||
All configuration is done in your sites config.php through definitions.
|
||||
The following snippet illustates how to configure the three core cache stores that require configuration.
|
||||
The following snippet illustrates how to configure the three core cache stores that require configuration.
|
||||
|
||||
define('TEST_CACHESTORE_MEMCACHE_TESTSERVERS', '127.0.0.1:11211');
|
||||
define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11211');
|
||||
define('TEST_CACHESTORE_MONGODB_TESTSERVER', 'mongodb://localhost:27017');
|
||||
|
||||
As of Moodle 2.8 it is also possible to set the default cache stores used when running unit tests.
|
||||
As of Moodle 2.8 it is also possible to set the default cache stores used when running tests.
|
||||
You can do this by adding the following define to your config.php file:
|
||||
|
||||
// xxx is one of Memcache, Memecached, mongodb or other cachestore with a test define.
|
||||
// xxx is one of Memcache, Memcached, mongodb or other cachestore with a test define.
|
||||
define('TEST_CACHE_USING_APPLICATION_STORE', 'xxx');
|
||||
|
||||
This allows you to run tests against a defined test store. It uses the defined value to identify a store to test against with a matching TEST_CACHESTORE define.
|
||||
Alternatively you can also run unit tests against an actual cache config.
|
||||
Alternatively you can also run tests against an actual cache config.
|
||||
To do this you must add the following to your config.php file:
|
||||
|
||||
define('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH', true');
|
||||
$CFG->altcacheconfigpath = '/a/temp/directory/yoursite.php'
|
||||
|
||||
This tells Moodle to use the config at $CFG->altcacheconfigpath when running unit tests.
|
||||
This tells Moodle to use the config at $CFG->altcacheconfigpath when running tests.
|
||||
There are a couple of considerations to using this method:
|
||||
* By setting $CFG->altcacheconfigpath your site will store the cache config in the specified path, not just the unit test cache config but your site config as well.
|
||||
* By setting $CFG->altcacheconfigpath your site will store the cache config in the specified path, not just the test cache config but your site config as well.
|
||||
* If you have configured your cache before setting $CFG->altcacheconfigpath you will need to copy it from moodledata/muc/config.php to the destination you specified.
|
||||
* This allows you to share a cache config between sites.
|
||||
* It also allows you to use unit tests to test your sites cache config.
|
||||
* It also allows you to use tests to test your sites cache config.
|
||||
|
||||
Please be aware that if you are using Memcache or Memcached it is recommended to use dedicated Memcached servers.
|
||||
When caches get purged the memcached servers you have configured get purged, any data stored within them whether it belongs to Moodle or not will be removed.
|
||||
|
||||
Vendored
+6
-5
@@ -126,8 +126,8 @@ class cache_factory {
|
||||
// situation. It will use disabled alternatives where available.
|
||||
require_once($CFG->dirroot.'/cache/disabledlib.php');
|
||||
self::$instance = new cache_factory_disabled();
|
||||
} else if (defined('PHPUNIT_TEST') && PHPUNIT_TEST) {
|
||||
// We're using the regular factory.
|
||||
} else if ((defined('PHPUNIT_TEST') && PHPUNIT_TEST) || behat_is_test_site()) {
|
||||
// We're using the test factory.
|
||||
require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
|
||||
self::$instance = new cache_phpunit_factory();
|
||||
if (defined('CACHE_DISABLE_STORES') && CACHE_DISABLE_STORES !== false) {
|
||||
@@ -335,10 +335,11 @@ class cache_factory {
|
||||
|
||||
// The class to use.
|
||||
$class = 'cache_config';
|
||||
$unittest = defined('PHPUNIT_TEST') && PHPUNIT_TEST;
|
||||
// Are we running tests of some form?
|
||||
$testing = (defined('PHPUNIT_TEST') && PHPUNIT_TEST) || behat_is_test_site();
|
||||
|
||||
// Check if this is a PHPUnit test and redirect to the phpunit config classes if it is.
|
||||
if ($unittest) {
|
||||
if ($testing) {
|
||||
require_once($CFG->dirroot.'/cache/locallib.php');
|
||||
require_once($CFG->dirroot.'/cache/tests/fixtures/lib.php');
|
||||
// We have just a single class for PHP unit tests. We don't care enough about its
|
||||
@@ -352,7 +353,7 @@ class cache_factory {
|
||||
|
||||
if ($writer || $needtocreate) {
|
||||
require_once($CFG->dirroot.'/cache/locallib.php');
|
||||
if (!$unittest) {
|
||||
if (!$testing) {
|
||||
$class .= '_writer';
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+4
-4
@@ -136,10 +136,10 @@ class cache_config_phpunittest extends cache_config_writer {
|
||||
|
||||
if (!empty($CFG->altcacheconfigpath)) {
|
||||
|
||||
if (defined('PHPUNIT_TEST') && PHPUNIT_TEST &&
|
||||
(!defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') || !TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH)) {
|
||||
// We're within a unit test, but TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH has not being defined or is
|
||||
// false, we want to use the default.
|
||||
// No need to check we are within a test here, this is the cache config class that gets used
|
||||
// only when one of those is true.
|
||||
if (!defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') || !TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH) {
|
||||
// TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH has not being defined or is false, we want to use the default.
|
||||
return $configpath;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -10,6 +10,7 @@ Information provided here is intended especially for developers.
|
||||
- cache_definition::load Argument 3 (final arg) is now unused.
|
||||
- cache_factory::create_cache_from_definition Argument 4 (final arg) is now unused.
|
||||
- cache::make Argument 4 (final arg) is now unused.
|
||||
* cache_config_phpunittest has been renamed to cache_config_testing
|
||||
|
||||
=== 2.7 ===
|
||||
* cache_store::is_ready is no longer abstract, calling cache_store::are_requirements_met by default.
|
||||
|
||||
Reference in New Issue
Block a user