From 634e657d23a276bc2bc241297eff468d59e3ffa3 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 7 Jan 2020 00:20:31 +0100 Subject: [PATCH 1/3] Replace Lock::acquire() with DI::lock()->acquire() --- src/Console/Lock.php | 6 ++-- src/Core/Lock.php | 15 --------- src/Core/Lock/CacheLock.php | 2 +- src/Core/Lock/DatabaseLock.php | 2 +- src/Core/Lock/ILock.php | 2 +- src/Core/Lock/SemaphoreLock.php | 2 +- src/Core/Update.php | 5 +-- src/Core/Worker.php | 8 ++--- src/Model/Item.php | 4 +-- src/Protocol/OStatus.php | 2 +- tests/Util/DbaLockMockTrait.php | 2 +- tests/src/Core/Lock/LockTest.php | 38 +++++++++++------------ tests/src/Core/Lock/SemaphoreLockTest.php | 2 +- 13 files changed, 38 insertions(+), 52 deletions(-) diff --git a/src/Console/Lock.php b/src/Console/Lock.php index 46826cc8c9..71de727028 100644 --- a/src/Console/Lock.php +++ b/src/Console/Lock.php @@ -156,11 +156,11 @@ HELP; } if (!empty($ttl) && !empty($timeout)) { - $result = $this->lock->acquireLock($lock, $timeout, $ttl); + $result = $this->lock->acquire($lock, $timeout, $ttl); } elseif (!empty($timeout)) { - $result = $this->lock->acquireLock($lock, $timeout); + $result = $this->lock->acquire($lock, $timeout); } else { - $result = $this->lock->acquireLock($lock); + $result = $this->lock->acquire($lock); } if ($result) { diff --git a/src/Core/Lock.php b/src/Core/Lock.php index e25feac2ec..a01ad88821 100644 --- a/src/Core/Lock.php +++ b/src/Core/Lock.php @@ -15,21 +15,6 @@ use Friendica\DI; */ class Lock { - /** - * @brief Acquires a lock for a given name - * - * @param string $key Name of the lock - * @param integer $timeout Seconds until we give up - * @param integer $ttl The Lock lifespan, must be one of the Cache constants - * - * @return boolean Was the lock successful? - * @throws \Exception - */ - public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES) - { - return DI::lock()->acquireLock($key, $timeout, $ttl); - } - /** * @brief Releases a lock if it was set by us * diff --git a/src/Core/Lock/CacheLock.php b/src/Core/Lock/CacheLock.php index 238beb705c..a4355cd085 100644 --- a/src/Core/Lock/CacheLock.php +++ b/src/Core/Lock/CacheLock.php @@ -30,7 +30,7 @@ class CacheLock extends Lock /** * (@inheritdoc) */ - public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES) + public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES) { $got_lock = false; $start = time(); diff --git a/src/Core/Lock/DatabaseLock.php b/src/Core/Lock/DatabaseLock.php index cecdc3966e..4d1b3080bc 100644 --- a/src/Core/Lock/DatabaseLock.php +++ b/src/Core/Lock/DatabaseLock.php @@ -35,7 +35,7 @@ class DatabaseLock extends Lock /** * (@inheritdoc) */ - public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES) + public function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES) { $got_lock = false; $start = time(); diff --git a/src/Core/Lock/ILock.php b/src/Core/Lock/ILock.php index d103d99191..082abbd70d 100644 --- a/src/Core/Lock/ILock.php +++ b/src/Core/Lock/ILock.php @@ -30,7 +30,7 @@ interface ILock * * @return boolean Was the lock successful? */ - public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES); + public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES); /** * Releases a lock if it was set by us diff --git a/src/Core/Lock/SemaphoreLock.php b/src/Core/Lock/SemaphoreLock.php index adfab5fc0e..64a105ec03 100644 --- a/src/Core/Lock/SemaphoreLock.php +++ b/src/Core/Lock/SemaphoreLock.php @@ -36,7 +36,7 @@ class SemaphoreLock extends Lock /** * (@inheritdoc) */ - public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES) + public function acquire($key, $timeout = 120, $ttl = Cache\Cache::FIVE_MINUTES) { self::$semaphore[$key] = sem_get(self::semaphoreKey($key)); if (!empty(self::$semaphore[$key])) { diff --git a/src/Core/Update.php b/src/Core/Update.php index 0ead704c10..5873f798e4 100644 --- a/src/Core/Update.php +++ b/src/Core/Update.php @@ -5,6 +5,7 @@ namespace Friendica\Core; use Friendica\App; use Friendica\Database\DBA; use Friendica\Database\DBStructure; +use Friendica\DI; use Friendica\Util\Strings; class Update @@ -95,7 +96,7 @@ class Update // Compare the current structure with the defined structure // If the Lock is acquired, never release it automatically to avoid double updates - if (Lock::acquire('dbupdate', 120, Cache::INFINITE)) { + if (DI::lock()->acquire('dbupdate', 120, Cache::INFINITE)) { // Checks if the build changed during Lock acquiring (so no double update occurs) $retryBuild = Config::get('system', 'build', null, true); @@ -181,7 +182,7 @@ class Update // If the update fails or times-out completely you may need to // delete the config entry to try again. - if (Lock::acquire('dbupdate_function', 120,Cache::INFINITE)) { + if (DI::lock()->acquire('dbupdate_function', 120,Cache::INFINITE)) { // call the specific update $retval = $funcname(); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 1eea922396..ed0f3a2e78 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -115,7 +115,7 @@ class Worker } // Trying to fetch new processes - but only once when successful - if (!$refetched && Lock::acquire('worker_process', 0)) { + if (!$refetched && DI::lock()->acquire('worker_process', 0)) { self::findWorkerProcesses(); Lock::release('worker_process'); self::$state = self::STATE_REFETCH; @@ -129,7 +129,7 @@ class Worker if (!self::getWaitingJobForPID()) { self::$state = self::STATE_LONG_LOOP; - if (Lock::acquire('worker', 0)) { + if (DI::lock()->acquire('worker', 0)) { // Count active workers and compare them with a maximum value that depends on the load if (self::tooMuchWorkers()) { Logger::log('Active worker limit reached, quitting.', Logger::DEBUG); @@ -933,7 +933,7 @@ class Worker } $stamp = (float)microtime(true); - if (!Lock::acquire('worker_process')) { + if (!DI::lock()->acquire('worker_process')) { return false; } self::$lock_duration += (microtime(true) - $stamp); @@ -1172,7 +1172,7 @@ class Worker } // If there is a lock then we don't have to check for too much worker - if (!Lock::acquire('worker', 0)) { + if (!DI::lock()->acquire('worker', 0)) { return $added; } diff --git a/src/Model/Item.php b/src/Model/Item.php index 4363a9a789..411608d677 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2060,7 +2060,7 @@ class Item } // To avoid timing problems, we are using locks. - $locked = Lock::acquire('item_insert_activity'); + $locked = DI::lock()->acquire('item_insert_activity'); if (!$locked) { Logger::log("Couldn't acquire lock for URI " . $item['uri'] . " - proceeding anyway."); } @@ -2103,7 +2103,7 @@ class Item } // To avoid timing problems, we are using locks. - $locked = Lock::acquire('item_insert_content'); + $locked = DI::lock()->acquire('item_insert_content'); if (!$locked) { Logger::log("Couldn't acquire lock for URI " . $item['uri'] . " - proceeding anyway."); } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 21659a6036..99702f9517 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -539,7 +539,7 @@ class OStatus Logger::log("Item with uri ".$item["uri"]." is from a blocked contact.", Logger::DEBUG); } else { // We are having duplicated entries. Hopefully this solves it. - if (Lock::acquire('ostatus_process_item_insert')) { + if (DI::lock()->acquire('ostatus_process_item_insert')) { $ret = Item::insert($item); Lock::release('ostatus_process_item_insert'); Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"].' stored. Return value: '.$ret); diff --git a/tests/Util/DbaLockMockTrait.php b/tests/Util/DbaLockMockTrait.php index 5b405dcfc2..035a859365 100644 --- a/tests/Util/DbaLockMockTrait.php +++ b/tests/Util/DbaLockMockTrait.php @@ -22,7 +22,7 @@ trait DbaLockMockTrait * @param null $time The current timestamp * @param null|int $times How often the method will get used * - *@see DatabaseLock::acquireLock() + *@see DatabaseLock::acquire() * */ public function mockAcquireLock($key, $ttl = Cache::FIVE_MINUTES, $locked = false, $pid = null, $rowExists = true, $time = null, $times = null) diff --git a/tests/src/Core/Lock/LockTest.php b/tests/src/Core/Lock/LockTest.php index 24efeaab86..269d48abd9 100644 --- a/tests/src/Core/Lock/LockTest.php +++ b/tests/src/Core/Lock/LockTest.php @@ -38,7 +38,7 @@ abstract class LockTest extends MockedTest public function testLock() { $this->assertFalse($this->instance->isLocked('foo')); - $this->assertTrue($this->instance->acquireLock('foo', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); $this->assertTrue($this->instance->isLocked('foo')); $this->assertFalse($this->instance->isLocked('bar')); } @@ -49,10 +49,10 @@ abstract class LockTest extends MockedTest public function testDoubleLock() { $this->assertFalse($this->instance->isLocked('foo')); - $this->assertTrue($this->instance->acquireLock('foo', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); $this->assertTrue($this->instance->isLocked('foo')); // We already locked it - $this->assertTrue($this->instance->acquireLock('foo', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); } /** @@ -61,7 +61,7 @@ abstract class LockTest extends MockedTest public function testReleaseLock() { $this->assertFalse($this->instance->isLocked('foo')); - $this->assertTrue($this->instance->acquireLock('foo', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); $this->assertTrue($this->instance->isLocked('foo')); $this->instance->releaseLock('foo'); $this->assertFalse($this->instance->isLocked('foo')); @@ -72,9 +72,9 @@ abstract class LockTest extends MockedTest */ public function testReleaseAll() { - $this->assertTrue($this->instance->acquireLock('foo', 1)); - $this->assertTrue($this->instance->acquireLock('bar', 1)); - $this->assertTrue($this->instance->acquireLock('nice', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); + $this->assertTrue($this->instance->acquire('bar', 1)); + $this->assertTrue($this->instance->acquire('nice', 1)); $this->assertTrue($this->instance->isLocked('foo')); $this->assertTrue($this->instance->isLocked('bar')); @@ -95,9 +95,9 @@ abstract class LockTest extends MockedTest $this->assertFalse($this->instance->isLocked('foo')); $this->assertFalse($this->instance->isLocked('bar')); $this->assertFalse($this->instance->isLocked('nice')); - $this->assertTrue($this->instance->acquireLock('foo', 1)); - $this->assertTrue($this->instance->acquireLock('bar', 1)); - $this->assertTrue($this->instance->acquireLock('nice', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); + $this->assertTrue($this->instance->acquire('bar', 1)); + $this->assertTrue($this->instance->acquire('nice', 1)); $this->assertTrue($this->instance->releaseLock('foo')); @@ -117,7 +117,7 @@ abstract class LockTest extends MockedTest public function testReleaseWitTTL() { $this->assertFalse($this->instance->isLocked('test')); - $this->assertTrue($this->instance->acquireLock('test', 1, 10)); + $this->assertTrue($this->instance->acquire('test', 1, 10)); $this->assertTrue($this->instance->isLocked('test')); $this->assertTrue($this->instance->releaseLock('test')); $this->assertFalse($this->instance->isLocked('test')); @@ -128,9 +128,9 @@ abstract class LockTest extends MockedTest */ public function testGetLocks() { - $this->assertTrue($this->instance->acquireLock('foo', 1)); - $this->assertTrue($this->instance->acquireLock('bar', 1)); - $this->assertTrue($this->instance->acquireLock('nice', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); + $this->assertTrue($this->instance->acquire('bar', 1)); + $this->assertTrue($this->instance->acquire('nice', 1)); $this->assertTrue($this->instance->isLocked('foo')); $this->assertTrue($this->instance->isLocked('bar')); @@ -148,9 +148,9 @@ abstract class LockTest extends MockedTest */ public function testGetLocksWithPrefix() { - $this->assertTrue($this->instance->acquireLock('foo', 1)); - $this->assertTrue($this->instance->acquireLock('test1', 1)); - $this->assertTrue($this->instance->acquireLock('test2', 1)); + $this->assertTrue($this->instance->acquire('foo', 1)); + $this->assertTrue($this->instance->acquire('test1', 1)); + $this->assertTrue($this->instance->acquire('test2', 1)); $this->assertTrue($this->instance->isLocked('foo')); $this->assertTrue($this->instance->isLocked('test1')); @@ -174,8 +174,8 @@ abstract class LockTest extends MockedTest $this->assertFalse($this->instance->isLocked('bar')); // TODO [nupplaphil] - Because of the Datetime-Utils for the database, we have to wait a FULL second between the checks to invalidate the db-locks/cache - $this->assertTrue($this->instance->acquireLock('foo', 2, 1)); - $this->assertTrue($this->instance->acquireLock('bar', 2, 3)); + $this->assertTrue($this->instance->acquire('foo', 2, 1)); + $this->assertTrue($this->instance->acquire('bar', 2, 3)); $this->assertTrue($this->instance->isLocked('foo')); $this->assertTrue($this->instance->isLocked('bar')); diff --git a/tests/src/Core/Lock/SemaphoreLockTest.php b/tests/src/Core/Lock/SemaphoreLockTest.php index 51d3866fe7..48c3b9f436 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -85,7 +85,7 @@ class SemaphoreLockTest extends LockTest touch($file); $this->assertTrue(file_exists($file)); - $this->assertTrue($this->instance->acquireLock('test')); + $this->assertTrue($this->instance->acquire('test')); $this->assertTrue($this->instance->isLocked('test')); $this->assertTrue($this->instance->releaseLock('test')); } From 31457b8566458efaeb20945cdfc56f6b6897dc53 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 7 Jan 2020 00:24:10 +0100 Subject: [PATCH 2/3] Replace Lock::release() with DI::lock()->release() and remove Core\Lock --- src/Console/Lock.php | 2 +- src/Core/Lock.php | 41 ----------------------- src/Core/Lock/CacheLock.php | 4 +-- src/Core/Lock/DatabaseLock.php | 2 +- src/Core/Lock/ILock.php | 2 +- src/Core/Lock/Lock.php | 2 +- src/Core/Lock/SemaphoreLock.php | 2 +- src/Core/Update.php | 16 ++++----- src/Core/Worker.php | 12 +++---- src/Model/Item.php | 6 ++-- src/Protocol/OStatus.php | 2 +- tests/Util/DbaLockMockTrait.php | 2 +- tests/src/Core/Lock/LockTest.php | 8 ++--- tests/src/Core/Lock/SemaphoreLockTest.php | 6 ++-- 14 files changed, 33 insertions(+), 74 deletions(-) delete mode 100644 src/Core/Lock.php diff --git a/src/Console/Lock.php b/src/Console/Lock.php index 71de727028..da1f408d0d 100644 --- a/src/Console/Lock.php +++ b/src/Console/Lock.php @@ -133,7 +133,7 @@ HELP; if (count($this->args) >= 2) { $lock = $this->getArgument(1); - if ($this->lock->releaseLock($lock, true)) { + if ($this->lock->release($lock, true)) { $this->out(sprintf('Lock \'%s\' released.', $lock)); } else { $this->out(sprintf('Couldn\'t release Lock \'%s\'', $lock)); diff --git a/src/Core/Lock.php b/src/Core/Lock.php deleted file mode 100644 index a01ad88821..0000000000 --- a/src/Core/Lock.php +++ /dev/null @@ -1,41 +0,0 @@ -releaseLock($key, $override); - } - - /** - * @brief Releases all lock that were set by us - * @return void - * @throws \Exception - */ - public static function releaseAll() - { - DI::lock()->releaseAll(); - } -} diff --git a/src/Core/Lock/CacheLock.php b/src/Core/Lock/CacheLock.php index a4355cd085..3eb0af765c 100644 --- a/src/Core/Lock/CacheLock.php +++ b/src/Core/Lock/CacheLock.php @@ -66,7 +66,7 @@ class CacheLock extends Lock /** * (@inheritdoc) */ - public function releaseLock($key, $override = false) + public function release($key, $override = false) { $cachekey = self::getLockKey($key); @@ -122,7 +122,7 @@ class CacheLock extends Lock $locks = $this->getLocks(); foreach ($locks as $lock) { - if (!$this->releaseLock($lock, $override)) { + if (!$this->release($lock, $override)) { $success = false; } } diff --git a/src/Core/Lock/DatabaseLock.php b/src/Core/Lock/DatabaseLock.php index 4d1b3080bc..0788f04b28 100644 --- a/src/Core/Lock/DatabaseLock.php +++ b/src/Core/Lock/DatabaseLock.php @@ -74,7 +74,7 @@ class DatabaseLock extends Lock /** * (@inheritdoc) */ - public function releaseLock($key, $override = false) + public function release($key, $override = false) { if ($override) { $where = ['name' => $key]; diff --git a/src/Core/Lock/ILock.php b/src/Core/Lock/ILock.php index 082abbd70d..121f29a436 100644 --- a/src/Core/Lock/ILock.php +++ b/src/Core/Lock/ILock.php @@ -40,7 +40,7 @@ interface ILock * * @return boolean Was the unlock successful? */ - public function releaseLock($key, $override = false); + public function release($key, $override = false); /** * Releases all lock that were set by us diff --git a/src/Core/Lock/Lock.php b/src/Core/Lock/Lock.php index f03ffe03d1..694384b72f 100644 --- a/src/Core/Lock/Lock.php +++ b/src/Core/Lock/Lock.php @@ -61,7 +61,7 @@ abstract class Lock implements ILock $return = true; foreach ($this->acquiredLocks as $acquiredLock => $hasLock) { - if (!$this->releaseLock($acquiredLock, $override)) { + if (!$this->release($acquiredLock, $override)) { $return = false; } } diff --git a/src/Core/Lock/SemaphoreLock.php b/src/Core/Lock/SemaphoreLock.php index 64a105ec03..1a28eb357c 100644 --- a/src/Core/Lock/SemaphoreLock.php +++ b/src/Core/Lock/SemaphoreLock.php @@ -55,7 +55,7 @@ class SemaphoreLock extends Lock * @param bool $override not necessary parameter for semaphore locks since the lock lives as long as the execution * of the using function */ - public function releaseLock($key, $override = false) + public function release($key, $override = false) { $success = false; diff --git a/src/Core/Update.php b/src/Core/Update.php index 5873f798e4..badbdc7851 100644 --- a/src/Core/Update.php +++ b/src/Core/Update.php @@ -74,7 +74,7 @@ class Update // In force mode, we release the dbupdate lock first // Necessary in case of an stuck update if ($override) { - Lock::release('dbupdate', true); + DI::lock()->release('dbupdate', true); } $build = Config::get('system', 'build', null, true); @@ -102,7 +102,7 @@ class Update $retryBuild = Config::get('system', 'build', null, true); if ($retryBuild !== $build) { Logger::info('Update already done.', ['from' => $stored, 'to' => $current]); - Lock::release('dbupdate'); + DI::lock()->release('dbupdate'); return ''; } @@ -111,7 +111,7 @@ class Update $r = self::runUpdateFunction($x, 'pre_update'); if (!$r) { Config::set('system', 'update', Update::FAILED); - Lock::release('dbupdate'); + DI::lock()->release('dbupdate'); return $r; } } @@ -127,7 +127,7 @@ class Update } Logger::error('Update ERROR.', ['from' => $stored, 'to' => $current, 'retval' => $retval]); Config::set('system', 'update', Update::FAILED); - Lock::release('dbupdate'); + DI::lock()->release('dbupdate'); return $retval; } else { Config::set('database', 'last_successful_update', $current); @@ -140,7 +140,7 @@ class Update $r = self::runUpdateFunction($x, 'update'); if (!$r) { Config::set('system', 'update', Update::FAILED); - Lock::release('dbupdate'); + DI::lock()->release('dbupdate'); return $r; } } @@ -151,7 +151,7 @@ class Update } Config::set('system', 'update', Update::SUCCESS); - Lock::release('dbupdate'); + DI::lock()->release('dbupdate'); } } } @@ -194,7 +194,7 @@ class Update L10n::t('Update %s failed. See error logs.', $x) ); Logger::error('Update function ERROR.', ['function' => $funcname, 'retval' => $retval]); - Lock::release('dbupdate_function'); + DI::lock()->release('dbupdate_function'); return false; } else { Config::set('database', 'last_successful_update_function', $funcname); @@ -204,7 +204,7 @@ class Update Config::set('system', 'build', $x); } - Lock::release('dbupdate_function'); + DI::lock()->release('dbupdate_function'); Logger::info('Update function finished.', ['function' => $funcname]); return true; } diff --git a/src/Core/Worker.php b/src/Core/Worker.php index ed0f3a2e78..086934fb8b 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -117,7 +117,7 @@ class Worker // Trying to fetch new processes - but only once when successful if (!$refetched && DI::lock()->acquire('worker_process', 0)) { self::findWorkerProcesses(); - Lock::release('worker_process'); + DI::lock()->release('worker_process'); self::$state = self::STATE_REFETCH; $refetched = true; } else { @@ -133,17 +133,17 @@ class Worker // Count active workers and compare them with a maximum value that depends on the load if (self::tooMuchWorkers()) { Logger::log('Active worker limit reached, quitting.', Logger::DEBUG); - Lock::release('worker'); + DI::lock()->release('worker'); return; } // Check free memory if (DI::process()->isMinMemoryReached()) { Logger::log('Memory limit reached, quitting.', Logger::DEBUG); - Lock::release('worker'); + DI::lock()->release('worker'); return; } - Lock::release('worker'); + DI::lock()->release('worker'); } } @@ -940,7 +940,7 @@ class Worker $found = self::findWorkerProcesses(); - Lock::release('worker_process'); + DI::lock()->release('worker_process'); if ($found) { $stamp = (float)microtime(true); @@ -1178,7 +1178,7 @@ class Worker // If there are already enough workers running, don't fork another one $quit = self::tooMuchWorkers(); - Lock::release('worker'); + DI::lock()->release('worker'); if ($quit) { return $added; diff --git a/src/Model/Item.php b/src/Model/Item.php index 411608d677..0fc1280c2b 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2076,11 +2076,11 @@ class Item } else { // This shouldn't happen. Logger::log('Could not insert activity for URI ' . $item['uri'] . ' - should not happen'); - Lock::release('item_insert_activity'); + DI::lock()->release('item_insert_activity'); return false; } if ($locked) { - Lock::release('item_insert_activity'); + DI::lock()->release('item_insert_activity'); } return true; } @@ -2121,7 +2121,7 @@ class Item Logger::log('Could not insert content for URI ' . $item['uri'] . ' - should not happen'); } if ($locked) { - Lock::release('item_insert_content'); + DI::lock()->release('item_insert_content'); } } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 99702f9517..2e47f18d16 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -541,7 +541,7 @@ class OStatus // We are having duplicated entries. Hopefully this solves it. if (DI::lock()->acquire('ostatus_process_item_insert')) { $ret = Item::insert($item); - Lock::release('ostatus_process_item_insert'); + DI::lock()->release('ostatus_process_item_insert'); Logger::log("Item with uri ".$item["uri"]." for user ".$importer["uid"].' stored. Return value: '.$ret); } else { $ret = Item::insert($item); diff --git a/tests/Util/DbaLockMockTrait.php b/tests/Util/DbaLockMockTrait.php index 035a859365..09bfd130c1 100644 --- a/tests/Util/DbaLockMockTrait.php +++ b/tests/Util/DbaLockMockTrait.php @@ -103,7 +103,7 @@ trait DbaLockMockTrait * @param null|int $pid The PID which was set * @param null|int $times How often the method will get used * - *@see DatabaseLock::releaseLock() + *@see DatabaseLock::release() * */ public function mockReleaseLock($key, $pid = null, $times = null) diff --git a/tests/src/Core/Lock/LockTest.php b/tests/src/Core/Lock/LockTest.php index 269d48abd9..70d7819d73 100644 --- a/tests/src/Core/Lock/LockTest.php +++ b/tests/src/Core/Lock/LockTest.php @@ -63,7 +63,7 @@ abstract class LockTest extends MockedTest $this->assertFalse($this->instance->isLocked('foo')); $this->assertTrue($this->instance->acquire('foo', 1)); $this->assertTrue($this->instance->isLocked('foo')); - $this->instance->releaseLock('foo'); + $this->instance->release('foo'); $this->assertFalse($this->instance->isLocked('foo')); } @@ -99,7 +99,7 @@ abstract class LockTest extends MockedTest $this->assertTrue($this->instance->acquire('bar', 1)); $this->assertTrue($this->instance->acquire('nice', 1)); - $this->assertTrue($this->instance->releaseLock('foo')); + $this->assertTrue($this->instance->release('foo')); $this->assertFalse($this->instance->isLocked('foo')); $this->assertTrue($this->instance->isLocked('bar')); @@ -119,7 +119,7 @@ abstract class LockTest extends MockedTest $this->assertFalse($this->instance->isLocked('test')); $this->assertTrue($this->instance->acquire('test', 1, 10)); $this->assertTrue($this->instance->isLocked('test')); - $this->assertTrue($this->instance->releaseLock('test')); + $this->assertTrue($this->instance->release('test')); $this->assertFalse($this->instance->isLocked('test')); } @@ -197,6 +197,6 @@ abstract class LockTest extends MockedTest public function testReleaseLockWithoutLock() { $this->assertFalse($this->instance->isLocked('wrongLock')); - $this->assertFalse($this->instance->releaseLock('wrongLock')); + $this->assertFalse($this->instance->release('wrongLock')); } } diff --git a/tests/src/Core/Lock/SemaphoreLockTest.php b/tests/src/Core/Lock/SemaphoreLockTest.php index 48c3b9f436..089d891cab 100644 --- a/tests/src/Core/Lock/SemaphoreLockTest.php +++ b/tests/src/Core/Lock/SemaphoreLockTest.php @@ -55,7 +55,7 @@ class SemaphoreLockTest extends LockTest touch($file); $this->assertTrue(file_exists($file)); - $this->assertFalse($this->instance->releaseLock('test', false)); + $this->assertFalse($this->instance->release('test', false)); $this->assertTrue(file_exists($file)); } @@ -72,7 +72,7 @@ class SemaphoreLockTest extends LockTest touch($file); $this->assertTrue(file_exists($file)); - $this->assertFalse($this->instance->releaseLock('test', true)); + $this->assertFalse($this->instance->release('test', true)); $this->assertTrue(file_exists($file)); } @@ -87,6 +87,6 @@ class SemaphoreLockTest extends LockTest $this->assertTrue(file_exists($file)); $this->assertTrue($this->instance->acquire('test')); $this->assertTrue($this->instance->isLocked('test')); - $this->assertTrue($this->instance->releaseLock('test')); + $this->assertTrue($this->instance->release('test')); } } From 17adcb5483840f867f98f8d8df3426c7586c3294 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 7 Jan 2020 00:57:30 +0100 Subject: [PATCH 3/3] Rename mock-methods --- tests/src/Console/LockConsoleTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/src/Console/LockConsoleTest.php b/tests/src/Console/LockConsoleTest.php index 51c05b5c37..dddc9daff1 100644 --- a/tests/src/Console/LockConsoleTest.php +++ b/tests/src/Console/LockConsoleTest.php @@ -68,7 +68,7 @@ class LockConsoleTest extends ConsoleTest public function testDelLock() { $this->lockMock - ->shouldReceive('releaseLock') + ->shouldReceive('release') ->with('test', true) ->andReturn(true) ->once(); @@ -83,7 +83,7 @@ class LockConsoleTest extends ConsoleTest public function testDelUnknownLock() { $this->lockMock - ->shouldReceive('releaseLock') + ->shouldReceive('release') ->with('test', true) ->andReturn(false) ->once(); @@ -103,7 +103,7 @@ class LockConsoleTest extends ConsoleTest ->andReturn(false) ->once(); $this->lockMock - ->shouldReceive('acquireLock') + ->shouldReceive('acquire') ->with('test') ->andReturn(true) ->once(); @@ -138,7 +138,7 @@ class LockConsoleTest extends ConsoleTest ->andReturn(false) ->once(); $this->lockMock - ->shouldReceive('acquireLock') + ->shouldReceive('acquire') ->with('test') ->andReturn(false) ->once();