Commit 667dd9ee authored by catch's avatar catch

Issue #1894960 by alexpott: Convert some lock tests to DrupalUnitTestBase.

parent 8215bf99
......@@ -29,54 +29,6 @@ public static function getInfo() {
);
}
/**
* Tests backend release functionality.
*/
public function testBackendLockRelease() {
$backend = lock();
$success = $backend->acquire('lock_a');
$this->assertTrue($success, 'Could acquire first lock.');
// This function is not part of the backend, but the default database
// backend implement it, we can here use it safely.
$is_free = $backend->lockMayBeAvailable('lock_a');
$this->assertFalse($is_free, 'First lock is unavailable.');
$backend->release('lock_a');
$is_free = $backend->lockMayBeAvailable('lock_a');
$this->assertTrue($is_free, 'First lock has been released.');
$success = $backend->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock.');
$success = $backend->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock a second time within the same request.');
$backend->release('lock_b');
}
/**
* Tests backend release functionality.
*/
public function testBackendLockReleaseAll() {
$backend = lock();
$success = $backend->acquire('lock_a');
$this->assertTrue($success, 'Could acquire first lock.');
$success = $backend->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock.');
$backend->releaseAll();
$is_free = $backend->lockMayBeAvailable('lock_a');
$this->assertTrue($is_free, 'First lock has been released.');
$is_free = $backend->lockMayBeAvailable('lock_b');
$this->assertTrue($is_free, 'Second lock has been released.');
}
/**
* Confirms that we can acquire and release locks in two parallel requests.
*/
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Lock\LockUnitTest.
*/
namespace Drupal\system\Tests\Lock;
use Drupal\Core\Lock\DatabaseLockBackend;
use Drupal\simpletest\DrupalUnitTestBase;
/**
* Tests the lock system.
*/
class LockUnitTest extends DrupalUnitTestBase {
/**
* Database lock backend to test.
*
* @var \Drupal\Core\Lock\DatabaseLockBackend
*/
protected $lock;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('system');
public static function getInfo() {
return array(
'name' => 'Locking framework unit tests',
'description' => 'Test the Database lock backend.',
'group' => 'Lock',
);
}
public function setUp() {
parent::setUp();
$this->lock = new DatabaseLockBackend();
$this->installSchema('system', 'semaphore');
}
/**
* Tests backend release functionality.
*/
public function testBackendLockRelease() {
$success = $this->lock->acquire('lock_a');
$this->assertTrue($success, 'Could acquire first lock.');
// This function is not part of the backend, but the default database
// backend implement it, we can here use it safely.
$is_free = $this->lock->lockMayBeAvailable('lock_a');
$this->assertFalse($is_free, 'First lock is unavailable.');
$this->lock->release('lock_a');
$is_free = $this->lock->lockMayBeAvailable('lock_a');
$this->assertTrue($is_free, 'First lock has been released.');
$success = $this->lock->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock.');
$success = $this->lock->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock a second time within the same request.');
$this->lock->release('lock_b');
}
/**
* Tests backend release functionality.
*/
public function testBackendLockReleaseAll() {
$success = $this->lock->acquire('lock_a');
$this->assertTrue($success, 'Could acquire first lock.');
$success = $this->lock->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock.');
$this->lock->releaseAll();
$is_free = $this->lock->lockMayBeAvailable('lock_a');
$this->assertTrue($is_free, 'First lock has been released.');
$is_free = $this->lock->lockMayBeAvailable('lock_b');
$this->assertTrue($is_free, 'Second lock has been released.');
}
}
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