Commit 00ae2056 authored by catch's avatar catch

Issue #1095608: fix simpletest compatibility and sync tests between 6.x and 7.x branches.

parent 931e6cf5
name = Memcache
description = High performance integration with memcache.
package = Caching
package = Performance and scalability
core = 7.x
files[] = memcache.inc
files[] = memcache.module
files[] = memcache.test
files[] = tests/memcache.test
files[] = tests/memcache-session.test
files[] = tests/memcache-lock.test
<?php
/**
* Implements hook_requirements().
*/
function memcache_requirements($phase) {
$requirements = array();
$t = get_t();
$memcache = extension_loaded('memcache');
$memcached = extension_loaded('memcached');
if ($phase == 'install' || $phase == 'runtime') {
if (!$memcache && !$memcached) {
$requirements['memcache_extension']['severity'] = REQUIREMENT_ERROR;
$requirements['memcache_extension']['title'] = $t('Extensions not available');
$requirements['memcache_extension']['value'] = $t('Either the <a href="http://php.net/manual/en/book.memcache.php">memcache</a> or <a href="http://php.net/manual/en/book.memcached.php">memcached</a> extensions must be installed in order to use memcache integration.');
}
}
if ($phase == 'runtime') {
if ($memcache) {
// @todo: consider adding minimum version requirement for extensions.
$requirements['memcache_extension_version']['severity'] = REQUIREMENT_OK;
$requirements['memcache_extension_version']['title'] = $t('Memcache version');
$requirements['memcache_extension_version']['value'] = phpversion('memcache');
}
if ($memcached) {
$requirements['memcached_extension_version']['severity'] = REQUIREMENT_OK;
$requirements['memcached_extension_version']['title'] = $t('Memcached version');
$requirements['memcached_extension_version']['value'] = phpversion('memcached');
}
// Confirm that dmemcache.inc has been included.
$requirements['memcache_inc']['title'] = $t('Memcache integration');
if (function_exists('dmemcache_set')) {
$requirements['memcache_inc']['severity'] = REQUIREMENT_OK;
$requirements['memcache_inc']['title'] = $t('Memcache integration');
$requirements['memcache_inc']['value'] = $t('Memcache integration functions are loaded');
}
else {
$requirements['memcache_inc']['severity'] = REQUIREMENT_WARNING;
$requirements['memcache_inc']['title'] = $t('Memcache integration');
$requirements['memcache_inc']['value'] = $t('Memcache integration is not currently loaded.');
$requirements['memcache_inc']['description'] = $t('Check README.txt and ensure that memcache.inc is configured correctly in settings.php');
}
}
return $requirements;
}
<?php
/**
* Provides very limited functionality such as hook_requirements().
* memcache.inc must be configured in settings.php, and memcache.module is not
* necessary to use memcache as a cache backend.
*/
name = Memcache Admin
description = Adds a User Interface to monitor the Memcache for this site.
package = Caching
core = 7.x
files[] = memcache_admin.module
package = Performance and scalability
<?php
/**
* Tests for the lock system.
*/
class MemcacheLockFunctionalTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Locking framework tests',
'description' => 'Confirm locking works between two separate requests.',
'group' => 'Memcache',
);
}
function setUp() {
parent::setUp('memcache_test');
}
/**
* Confirm that we can acquire and release locks in two parallel requests.
*/
function testLockAcquire() {
// Nasty hack. There are two processes involved here - the process
// calling the test itself, that calls lock_acquire() directly. And the
// 'child' process that is requested over http by drupalGet().
// In dmemcache.inc, we look for simpletest installs, to force a
// simpletest prefix as part of the memcache key - this avoids the
// actual Drupal site install being corrupted by entries from the tested
// site. However, the child install apparently does not set the simpletest
// global, so when making requests to that site, we pass the simpletest ID
// as part of the URL, and mess around with the globals on that side.
$test_run_id = $GLOBALS['drupal_test_info']['test_run_id'];
$lock_acquired = 'TRUE: Lock successfully acquired in memcache_test_lock_acquire()';
$lock_not_acquired = 'FALSE: Lock not acquired in memcache_test_lock_acquire()';
$this->assertTrue(lock_acquire('memcache_test_lock_acquire'), t('Lock acquired by this request.'), t('Lock'));
$this->assertTrue(lock_acquire('memcache_test_lock_acquire'), t('Lock extended by this request.'), t('Lock'));
lock_release('memcache_test_lock_acquire');
// Cause another request to acquire the lock.
$this->drupalGet('memcache-test/lock-acquire' . "/$test_run_id");
$this->assertText($lock_acquired, t('Lock acquired by the other request.'), t('Lock'));
// The other request has finished, thus it should have released its lock.
$this->assertTrue(lock_acquire('memcache_test_lock_acquire'), t('Lock acquired by this request.'), t('Lock'));
// This request holds the lock, so the other request cannot acquire it.
$this->drupalGet('memcache-test/lock-acquire' . "/$test_run_id");
$this->assertText($lock_not_acquired, t('Lock not acquired by the other request.'), t('Lock'));
lock_release('memcache_test_lock_acquire');
// Try a very short timeout and lock breaking.
$this->assertTrue(lock_acquire('memcache_test_lock_acquire', 1), t('Lock acquired by this request.'), t('Lock'));
sleep(2);
// The other request should break our lock.
$this->drupalGet('memcache-test/lock-acquire' . "/$test_run_id");
$this->assertText($lock_acquired, t('Lock acquired by the other request, breaking our lock.'), t('Lock'));
// We cannot renew it, since the other thread took it.
// @todo: this assertion currently fails - the lock_acquire() call returns
// true. For now, commented out the assertion, uncomment when attempting to
// fix.
//$this->assertFalse(lock_acquire('memcache_test_lock_acquire'), t('Lock cannot be extended by this request.'), t('Lock'));
// Check the shut-down function.
$lock_acquired_exit = 'TRUE: Lock successfully acquired in memcache_test_lock_exit()';
$lock_not_acquired_exit = 'FALSE: Lock not acquired in memcache_test_lock_exit()';
$this->drupalGet('memcache-test/lock-exit' . "/$test_run_id");
$this->assertText($lock_acquired_exit, t('Lock acquired by the other request before exit.'), t('Lock'));
$this->assertTrue(lock_acquire('memcache_test_lock_exit'), t('Lock acquired by this request after the other request exits.'), t('Lock'));
}
}
This diff is collapsed.
This diff is collapsed.
name = Memcache test
description = Support module for memcache testing.
package = Testing
core = 7.x
hidden = TRUE
<?php
/**
* Implements hook_menu().
*/
function memcache_test_menu() {
$items['memcache-test/lock-acquire'] = array(
'title' => 'Lock acquire',
'page callback' => 'memcache_test_lock_acquire',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['memcache-test/lock-exit'] = array(
'title' => 'Lock acquire then exit',
'page callback' => 'memcache_test_lock_exit',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Try to acquire a named lock and report the outcome.
*/
function memcache_test_lock_acquire() {
dmemcache_key(FALSE, FALSE, TRUE);
$GLOBALS['drupal_test_info']['test_run_id'] = arg(2);
if (lock_acquire('memcache_test_lock_acquire')) {
lock_release('memcache_test_lock_acquire');
return 'TRUE: Lock successfully acquired in memcache_test_lock_acquire()';
}
else {
return 'FALSE: Lock not acquired in memcache_test_lock_acquire()';
}
}
/**
* Try to acquire a specific lock, and then exit.
*/
function memcache_test_lock_exit() {
dmemcache_key(FALSE, FALSE, TRUE);
$GLOBALS['drupal_test_info']['test_run_id'] = arg(2);
if (lock_acquire('memcache_test_lock_exit', 900)) {
echo 'TRUE: Lock successfully acquired in memcache_test_lock_exit()';
// The shut-down function should release the lock.
exit();
}
else {
return 'FALSE: Lock not acquired in memcache_test_lock_exit()';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment