2018-07-04 21:37:22 +00:00
|
|
|
<?php
|
|
|
|
|
2018-07-05 18:57:31 +00:00
|
|
|
namespace Friendica\Test\src\Core\Lock;
|
2018-07-04 21:37:22 +00:00
|
|
|
|
2019-01-30 19:26:17 +00:00
|
|
|
use Friendica\Core\Cache;
|
2018-07-04 21:37:22 +00:00
|
|
|
use Friendica\Core\Lock\DatabaseLockDriver;
|
2019-01-30 19:26:17 +00:00
|
|
|
use Friendica\Test\Util\DbaLockMockTrait;
|
2018-07-04 21:37:22 +00:00
|
|
|
|
2018-11-05 07:51:35 +00:00
|
|
|
/**
|
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
2018-07-04 21:37:22 +00:00
|
|
|
class DatabaseLockDriverTest extends LockTest
|
|
|
|
{
|
2019-01-30 19:26:17 +00:00
|
|
|
use DbaLockMockTrait;
|
|
|
|
|
|
|
|
protected $pid = 123;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->mockConnected();
|
|
|
|
$this->mockConnect();
|
|
|
|
|
|
|
|
$this->mockReleaseAll($this->pid, 2);
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
2018-07-04 21:37:22 +00:00
|
|
|
protected function getInstance()
|
|
|
|
{
|
2019-01-30 19:26:17 +00:00
|
|
|
return new DatabaseLockDriver($this->pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLock()
|
|
|
|
{
|
|
|
|
$this->mockIsLocked('foo', false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('foo', true, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('bar', false, $this->startTime, 1);
|
|
|
|
|
|
|
|
parent::testLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDoubleLock()
|
|
|
|
{
|
|
|
|
$this->mockIsLocked('foo', false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('foo', true, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('foo', Cache::FIVE_MINUTES, true, $this->pid, true, $this->startTime, 1);
|
|
|
|
|
|
|
|
parent::testDoubleLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReleaseLock()
|
|
|
|
{
|
|
|
|
$this->mockIsLocked('foo', false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('foo', true, $this->startTime, 1);
|
|
|
|
$this->mockReleaseLock('foo', $this->pid, 1);
|
|
|
|
$this->mockIsLocked('foo', false, $this->startTime, 1);
|
|
|
|
|
|
|
|
parent::testReleaseLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReleaseAll()
|
|
|
|
{
|
|
|
|
$this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('bar', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('nice', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
|
|
|
|
$this->mockIsLocked('foo', true, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('bar', true, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('nice', true, $this->startTime, 1);
|
|
|
|
|
|
|
|
$this->mockReleaseAll($this->pid, 1);
|
|
|
|
|
|
|
|
$this->mockIsLocked('foo', false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('bar', false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('nice', false, $this->startTime, 1);
|
|
|
|
|
|
|
|
parent::testReleaseAll();
|
2018-07-04 21:37:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 19:26:17 +00:00
|
|
|
public function testReleaseAfterUnlock()
|
2018-07-04 21:37:22 +00:00
|
|
|
{
|
2019-01-30 19:26:17 +00:00
|
|
|
$this->mockIsLocked('foo', false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('bar', false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('nice', false, $this->startTime, 1);
|
|
|
|
|
|
|
|
$this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('bar', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('nice', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
|
|
|
|
$this->mockReleaseLock('foo', $this->pid, 1);
|
|
|
|
|
|
|
|
$this->mockIsLocked('foo', false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('bar', true, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('nice', true, $this->startTime, 1);
|
|
|
|
|
|
|
|
$this->mockReleaseAll($this->pid, 1);
|
|
|
|
|
|
|
|
$this->mockIsLocked('bar', false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('nice', false, $this->startTime, 1);
|
|
|
|
|
|
|
|
parent::testReleaseAfterUnlock();
|
2018-07-04 21:37:22 +00:00
|
|
|
}
|
2019-03-04 20:28:36 +00:00
|
|
|
|
|
|
|
public function testReleaseWitTTL()
|
|
|
|
{
|
|
|
|
$this->mockIsLocked('test', false, $this->startTime, 1);
|
|
|
|
$this->mockAcquireLock('test', 10, false, $this->pid, false, $this->startTime, 1);
|
|
|
|
$this->mockIsLocked('test', true, $this->startTime, 1);
|
|
|
|
$this->mockReleaseLock('test', $this->pid, 1);
|
|
|
|
$this->mockIsLocked('test', false, $this->startTime, 1);
|
|
|
|
|
|
|
|
parent::testReleaseWitTTL();
|
|
|
|
}
|
2018-07-07 14:15:03 +00:00
|
|
|
}
|