<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
namespace Friendica\Test\src\Core\Lock;
-use Friendica\Core\Cache;
-use Friendica\Core\Lock\DatabaseLockDriver;
-use Friendica\Test\Util\DbaLockMockTrait;
+use Friendica\Core\Lock\Type\DatabaseLock;
+use Friendica\Core\Config\Factory\Config;
+use Friendica\DI;
+use Friendica\Test\DatabaseTestTrait;
+use Friendica\Test\Util\Database\StaticDatabase;
+use Friendica\Test\Util\VFSTrait;
+use Friendica\Util\Profiler;
+use Mockery;
+use Psr\Log\NullLogger;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- */
class DatabaseLockDriverTest extends LockTest
{
- use DbaLockMockTrait;
+ use VFSTrait;
+ use DatabaseTestTrait;
protected $pid = 123;
- protected function setUp()
+ protected function setUp(): void
{
- $this->mockConnected();
- $this->mockConnect();
+ $this->setUpVfsDir();
- $this->mockReleaseAll($this->pid, 2);
+ $this->setUpDb();
parent::setUp();
}
protected function getInstance()
{
- 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();
+ return new DatabaseLock(DI::dba(), $this->pid);
}
- public function testReleaseAfterUnlock()
+ protected function tearDown(): void
{
- $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);
+ $this->tearDownDb();
- parent::testReleaseAfterUnlock();
+ parent::tearDown();
}
}