Exemplo n.º 1
0
 public function test_RedisLock_LockTime()
 {
     $key = static::TEST_KEY;
     $RedisLock = new RedisLock(static::$Redis, $key);
     $RedisLock2 = new RedisLock(static::$Redis, $key);
     for ($i = 1; $i <= 5; $i++) {
         $microtime = microtime(true);
         $this->assertTrue($RedisLock->acquire(self::LOCK_MIN_TIME * $i));
         $this->assertTrue($RedisLock->isLocked());
         $this->assertTrue($RedisLock->isExists());
         $this->assertFalse($RedisLock2->isLocked());
         $this->assertTrue($RedisLock2->isExists());
         //$microtime = microtime(true);
         $this->assertTrue($RedisLock2->acquire(self::LOCK_MIN_TIME * $i, $i + 1));
         $waitTime = microtime(true) - $microtime;
         $this->assertTrue($RedisLock2->update(1));
         $this->assertGreaterThan(self::LOCK_MIN_TIME * $i - 1, $waitTime);
         $this->assertLessThanOrEqual(self::LOCK_MIN_TIME * $i + 1, $waitTime);
         try {
             $RedisLock->isLocked();
             $this->assertFalse('Expect LostLockException');
         } catch (\Exception $Ex) {
             $this->assertInstanceOf(LostLockException::class, $Ex);
         }
         $this->assertTrue($RedisLock->isExists());
         $this->assertTrue($RedisLock2->isLocked());
         $this->assertTrue($RedisLock2->isExists());
         $this->assertTrue($RedisLock2->release());
     }
 }