X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FCore%2FLock%2FDatabaseLockDriverTest.php;h=297e76d50b0fd25c70613fbe10aaefac1fef5a90;hb=f4ec7c47b921209b5ff7906bee8aba9db326d0cb;hp=f55ab0f9e26f54145b9cc28449ac89ed7e087e55;hpb=1ffe0cfd818ad48f7c227915d3abf68d26d8a06c;p=friendica.git diff --git a/tests/src/Core/Lock/DatabaseLockDriverTest.php b/tests/src/Core/Lock/DatabaseLockDriverTest.php index f55ab0f9e2..297e76d50b 100644 --- a/tests/src/Core/Lock/DatabaseLockDriverTest.php +++ b/tests/src/Core/Lock/DatabaseLockDriverTest.php @@ -2,23 +2,117 @@ namespace Friendica\Test\src\Core\Lock; -use dba; +use Friendica\Core\Cache; use Friendica\Core\Lock\DatabaseLockDriver; -use Friendica\Database\DBStructure; -use PHPUnit\DbUnit\DataSet\YamlDataSet; -use PHPUnit\DbUnit\TestCaseTrait; -use PHPUnit_Extensions_Database_DB_IDatabaseConnection; +use Friendica\Test\Util\DbaLockMockTrait; +/** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ class DatabaseLockDriverTest extends LockTest { + use DbaLockMockTrait; + + protected $pid = 123; + + protected function setUp() + { + $this->mockConnected(); + $this->mockConnect(); + + $this->mockReleaseAll($this->pid, 2); + + parent::setUp(); + } + protected function getInstance() { - return new DatabaseLockDriver(); + 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(); + } + + public function testReleaseAfterUnlock() + { + $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(); } - public function tearDown() + public function testReleaseWitTTL() { - dba::delete('locks', [ 'id > 0']); - parent::tearDown(); + $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(); } }