mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-56273 cache: Fixed initialise call
After store is created, it should be checked if it's ready before calling initialise
This commit is contained in:
parent
cad8adccc7
commit
4a910b9aa6
4
cache/classes/dummystore.php
vendored
4
cache/classes/dummystore.php
vendored
@ -258,7 +258,9 @@ class cachestore_dummy extends cache_store {
|
||||
*/
|
||||
public static function initialise_test_instance(cache_definition $definition) {
|
||||
$cache = new cachestore_dummy('Dummy store test');
|
||||
$cache->initialise($definition);
|
||||
if ($cache->is_ready()) {
|
||||
$cache->initialise($definition);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
|
||||
|
10
cache/stores/apcu/lib.php
vendored
10
cache/stores/apcu/lib.php
vendored
@ -155,15 +155,6 @@ class cachestore_apcu extends cache_store implements cache_is_key_aware, cache_i
|
||||
return ($this->definition !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this cache store instance is ready to use.
|
||||
* @return bool
|
||||
*/
|
||||
public function is_ready() {
|
||||
// No set up is actually required, providing apc is installed and enabled.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the given key for use.
|
||||
*
|
||||
@ -325,6 +316,7 @@ class cachestore_apcu extends cache_store implements cache_is_key_aware, cache_i
|
||||
}
|
||||
$name = 'APCu test';
|
||||
$cache = new cachestore_apcu($name);
|
||||
// No need to check if is_ready() as this has already being done by requirement check.
|
||||
$cache->initialise($definition);
|
||||
return $cache;
|
||||
}
|
||||
|
4
cache/stores/file/lib.php
vendored
4
cache/stores/file/lib.php
vendored
@ -673,7 +673,9 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
|
||||
$name = 'File test';
|
||||
$path = make_cache_directory('cachestore_file_test');
|
||||
$cache = new cachestore_file($name, array('path' => $path));
|
||||
$cache->initialise($definition);
|
||||
if ($cache->is_ready()) {
|
||||
$cache->initialise($definition);
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
|
||||
|
4
cache/stores/memcache/lib.php
vendored
4
cache/stores/memcache/lib.php
vendored
@ -576,7 +576,9 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
|
||||
}
|
||||
|
||||
$store = new cachestore_memcache('Test memcache', $configuration);
|
||||
$store->initialise($definition);
|
||||
if ($store->is_ready()) {
|
||||
$store->initialise($definition);
|
||||
}
|
||||
|
||||
return $store;
|
||||
}
|
||||
|
@ -58,12 +58,12 @@ class cachestore_memcache_test extends cachestore_tests {
|
||||
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcache', 'phpunit_test');
|
||||
$instance = new cachestore_memcache('Memcache Test', cachestore_memcache::unit_test_configuration());
|
||||
$instance->initialise($definition);
|
||||
|
||||
if (!$instance->is_ready()) {
|
||||
// Something prevented memcache store to be inited (extension, TEST_CACHESTORE_MEMCACHE_TESTSERVERS...).
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
$instance->initialise($definition);
|
||||
|
||||
$keys = array(
|
||||
// Alphanumeric.
|
||||
|
5
cache/stores/memcached/lib.php
vendored
5
cache/stores/memcached/lib.php
vendored
@ -733,7 +733,10 @@ class cachestore_memcached extends cache_store implements cache_is_configurable
|
||||
}
|
||||
|
||||
$store = new cachestore_memcached($name, $configuration);
|
||||
$store->initialise($definition);
|
||||
// If store is ready then only initialise.
|
||||
if ($store->is_ready()) {
|
||||
$store->initialise($definition);
|
||||
}
|
||||
|
||||
return $store;
|
||||
}
|
||||
|
@ -62,12 +62,12 @@ class cachestore_memcached_test extends cachestore_tests {
|
||||
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcached', 'phpunit_test');
|
||||
$instance = new cachestore_memcached('Memcached Test', cachestore_memcached::unit_test_configuration());
|
||||
$instance->initialise($definition);
|
||||
|
||||
if (!$instance->is_ready()) {
|
||||
// Something prevented memcached store to be inited (extension, TEST_CACHESTORE_MEMCACHED_TESTSERVERS...).
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
$instance->initialise($definition);
|
||||
|
||||
$keys = array(
|
||||
// Alphanumeric.
|
||||
@ -183,7 +183,7 @@ class cachestore_memcached_test extends cachestore_tests {
|
||||
set_config('testname', $testserver, 'cachestore_memcached');
|
||||
set_config('testservers', $testserver, 'cachestore_memcached');
|
||||
$checkinstance = cachestore_memcached::initialise_test_instance($definition);
|
||||
if (!$checkinstance) {
|
||||
if (!$checkinstance->is_ready()) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
$checkinstances[] = $checkinstance;
|
||||
|
2
cache/stores/mongodb/tests/mongodb_test.php
vendored
2
cache/stores/mongodb/tests/mongodb_test.php
vendored
@ -57,11 +57,11 @@ class cachestore_mongodb_test extends cachestore_tests {
|
||||
// This generates a definition that has a hash starting with a number. MDL-46208.
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_mongodb', 'abc');
|
||||
$instance = new cachestore_mongodb('MongoDB_Test', cachestore_mongodb::unit_test_configuration());
|
||||
$instance->initialise($definition);
|
||||
|
||||
if (!$instance->is_ready()) {
|
||||
$this->markTestSkipped();
|
||||
}
|
||||
$instance->initialise($definition);
|
||||
|
||||
$this->assertTrue($instance->set(1, 'alpha'));
|
||||
$this->assertTrue($instance->set(2, 'beta'));
|
||||
|
6
cache/tests/fixtures/stores.php
vendored
6
cache/tests/fixtures/stores.php
vendored
@ -63,33 +63,33 @@ abstract class cachestore_tests extends advanced_testcase {
|
||||
if ($modes & cache_store::MODE_APPLICATION) {
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, $class, 'phpunit_test');
|
||||
$instance = new $class($class.'_test', $class::unit_test_configuration());
|
||||
$instance->initialise($definition);
|
||||
|
||||
if (!$instance->is_ready()) {
|
||||
$this->markTestSkipped('Could not test '.$class.'. No test instance configured for application caches.');
|
||||
} else {
|
||||
$instance->initialise($definition);
|
||||
$this->run_tests($instance);
|
||||
}
|
||||
}
|
||||
if ($modes & cache_store::MODE_SESSION) {
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_SESSION, $class, 'phpunit_test');
|
||||
$instance = new $class($class.'_test', $class::unit_test_configuration());
|
||||
$instance->initialise($definition);
|
||||
|
||||
if (!$instance->is_ready()) {
|
||||
$this->markTestSkipped('Could not test '.$class.'. No test instance configured for session caches.');
|
||||
} else {
|
||||
$instance->initialise($definition);
|
||||
$this->run_tests($instance);
|
||||
}
|
||||
}
|
||||
if ($modes & cache_store::MODE_REQUEST) {
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, $class, 'phpunit_test');
|
||||
$instance = new $class($class.'_test', $class::unit_test_configuration());
|
||||
$instance->initialise($definition);
|
||||
|
||||
if (!$instance->is_ready()) {
|
||||
$this->markTestSkipped('Could not test '.$class.'. No test instance configured for request caches.');
|
||||
} else {
|
||||
$instance->initialise($definition);
|
||||
$this->run_tests($instance);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user