123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- class LockFunctionalTest extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Locking framework tests',
- 'description' => 'Confirm locking works between two separate requests.',
- 'group' => 'System',
- );
- }
- function setUp() {
- parent::setUp('system_test');
- }
-
- function testLockAcquire() {
- $lock_acquired = 'TRUE: Lock successfully acquired in system_test_lock_acquire()';
- $lock_not_acquired = 'FALSE: Lock not acquired in system_test_lock_acquire()';
- $this->assertTrue(lock_acquire('system_test_lock_acquire'), 'Lock acquired by this request.', 'Lock');
- $this->assertTrue(lock_acquire('system_test_lock_acquire'), 'Lock extended by this request.', 'Lock');
- lock_release('system_test_lock_acquire');
-
- $this->drupalGet('system-test/lock-acquire');
- $this->assertText($lock_acquired, 'Lock acquired by the other request.', 'Lock');
-
- $this->assertTrue(lock_acquire('system_test_lock_acquire'), 'Lock acquired by this request.', 'Lock');
-
- $this->drupalGet('system-test/lock-acquire');
- $this->assertText($lock_not_acquired, 'Lock not acquired by the other request.', 'Lock');
- lock_release('system_test_lock_acquire');
-
- $this->assertTrue(lock_acquire('system_test_lock_acquire', 0.5), 'Lock acquired by this request.', 'Lock');
- sleep(1);
-
- $this->drupalGet('system-test/lock-acquire');
- $this->assertText($lock_acquired, 'Lock acquired by the other request, breaking our lock.', 'Lock');
-
- $this->assertFalse(lock_acquire('system_test_lock_acquire'), 'Lock cannot be extended by this request.', 'Lock');
-
- $lock_acquired_exit = 'TRUE: Lock successfully acquired in system_test_lock_exit()';
- $lock_not_acquired_exit = 'FALSE: Lock not acquired in system_test_lock_exit()';
- $this->drupalGet('system-test/lock-exit');
- $this->assertText($lock_acquired_exit, 'Lock acquired by the other request before exit.', 'Lock');
- $this->assertTrue(lock_acquire('system_test_lock_exit'), 'Lock acquired by this request after the other request exits.', 'Lock');
- }
- }
|