public function LockFunctionalTest::testBackendLockRelease

Tests backend release functionality.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Lock/LockFunctionalTest.php, line 35
Definition of Drupal\system\Tests\Lock\LockFunctionalTest.

Class

LockFunctionalTest
Tests the lock system.

Namespace

Drupal\system\Tests\Lock

Code

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');
}