You are here

public function Redis_Tests_Lock_AbstractLockingUnitTestCase::testLock in Redis 7.2

File

lib/Redis/Tests/Lock/AbstractLockingUnitTestCase.php, line 48

Class

Redis_Tests_Lock_AbstractLockingUnitTestCase

Code

public function testLock() {
  $b1 = $this
    ->createLockBackend();
  $b2 = $this
    ->createLockBackend();
  $s = $b1
    ->lockAcquire('test1', 20000);
  $this
    ->assertTrue($s, "Lock test1 acquired");
  $s = $b1
    ->lockAcquire('test1', 20000);
  $this
    ->assertTrue($s, "Lock test1 acquired a second time by the same thread");
  $s = $b2
    ->lockAcquire('test1', 20000);
  $this
    ->assertFalse($s, "Lock test1 could not be acquired by another thread");
  $b2
    ->lockRelease('test1');
  $s = $b2
    ->lockAcquire('test1');
  $this
    ->assertFalse($s, "Lock test1 could not be released by another thread");
  $b1
    ->lockRelease('test1');
  $s = $b2
    ->lockAcquire('test1');
  $this
    ->assertTrue($s, "Lock test1 has been released by the first thread");
}