Commit 7c2afb2f authored by catch's avatar catch
Browse files

Issue #3540554 by tstoeckler: Functional tests attempting to release locks for...

Issue #3540554 by tstoeckler: Functional tests attempting to release locks for a no-longer existing site throws an exception

(cherry picked from commit 5477c043)
parent f4881015
Loading
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -165,10 +165,17 @@ public function releaseAll($lock_id = NULL) {
      if (empty($lock_id)) {
        $lock_id = $this->getLockId();
      }
      // In functional tests the test site may have been removed before the
      // final request has been terminated.
      try {
        $this->database->delete('semaphore')
          ->condition('value', $lock_id)
          ->execute();
      }
      catch (\Exception $e) {
        $this->catchException($e);
      }
    }
  }

  /**
+12 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\KernelTests\Core\Lock;

use Drupal\Core\Database\Database;
use Drupal\Core\Lock\DatabaseLockBackend;
use Drupal\KernelTests\KernelTestBase;

@@ -86,6 +87,17 @@ public function testBackendLockReleaseAll(): void {

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

}