memcache-lock.test in Zircon Profile 8.0
File
modules/memcache/tests/memcache-lock.test
View source
<?php
class MemcacheLockFunctionalTest extends DrupalWebTestCase {
protected $profile = 'testing';
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');
}
function testLockAcquire() {
$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');
$this
->drupalGet('memcache-test/lock-acquire' . "/{$test_run_id}");
$this
->assertText($lock_acquired, t('Lock acquired by the other request.'), t('Lock'));
$this
->assertTrue(lock_acquire('memcache_test_lock_acquire'), t('Lock acquired by this request.'), t('Lock'));
$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');
$this
->assertTrue(lock_acquire('memcache_test_lock_acquire', 1), t('Lock acquired by this request.'), t('Lock'));
sleep(2);
$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'));
$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'));
}
}