function LockTest::testBackendLockReleaseAll

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest::testBackendLockReleaseAll()
  2. 10 core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest::testBackendLockReleaseAll()
  3. 9 core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest::testBackendLockReleaseAll()
  4. 8.9.x core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest::testBackendLockReleaseAll()

Tests backend release functionality.

File

core/tests/Drupal/KernelTests/Core/Lock/LockTest.php, line 78

Class

LockTest
Tests the Database lock backend.

Namespace

Drupal\KernelTests\Core\Lock

Code

public function testBackendLockReleaseAll() : void {
  $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.');
  // Test that the semaphore table having been removed does not cause
  // exceptions.
  $success = $this->lock
    ->acquire('lock_a');
  $this->assertTrue($success, 'Could re-acquire first lock.');
  Database::getConnection()->schema()
    ->dropTable('semaphore');
  $this->lock
    ->releaseAll();
  $is_free = $this->lock
    ->lockMayBeAvailable('lock_a');
  $this->assertTrue($is_free, 'Re-acquired lock has been released.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.