X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FCore%2FLock%2FDatabaseLockDriverTest.php;h=297e76d50b0fd25c70613fbe10aaefac1fef5a90;hb=8660f6d86fc5d8f8f997b4b6a537b80d7ffbedff;hp=c6ded6e3d7a667f0cff10b6f9f1e1364ec4862bb;hpb=906bb25972bf3f23e6cc3b98a50c0f3fa0990964;p=friendica.git diff --git a/tests/src/Core/Lock/DatabaseLockDriverTest.php b/tests/src/Core/Lock/DatabaseLockDriverTest.php index c6ded6e3d7..297e76d50b 100644 --- a/tests/src/Core/Lock/DatabaseLockDriverTest.php +++ b/tests/src/Core/Lock/DatabaseLockDriverTest.php @@ -1,67 +1,118 @@ module = 'install'; - - // Create database structure - DBStructure::update(false, true, true); - } else { - $this->markTestSkipped('Could not connect to the database.'); - } - } - - return $this->createDefaultDBConnection(dba::get_db(), getenv('DB')); + $this->mockConnected(); + $this->mockConnect(); + + $this->mockReleaseAll($this->pid, 2); + + parent::setUp(); } - /** - * Get dataset to populate the database with. - * @return YamlDataSet - * @see https://phpunit.de/manual/5.7/en/database.html - */ - protected function getDataSet() + protected function getInstance() { - return new YamlDataSet(__DIR__ . '/../../../datasets/api.yml'); + return new DatabaseLockDriver($this->pid); } - protected function getInstance() + 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() { - return new DatabaseLockDriver(); + $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(); } -} \ No newline at end of file +}