mirror of
https://github.com/friendica/friendica
synced 2024-11-11 22:22:53 +00:00
Merge branch 'develop' of https://github.com/friendica/friendica into develop
This commit is contained in:
commit
0bc2fe66f5
10 changed files with 58 additions and 85 deletions
|
@ -53,6 +53,11 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
|
||||||
*/
|
*/
|
||||||
public function clear($outdated = true)
|
public function clear($outdated = true)
|
||||||
{
|
{
|
||||||
|
// Array doesn't support TTL so just don't delete something
|
||||||
|
if ($outdated) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$this->cachedData = [];
|
$this->cachedData = [];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,12 +117,14 @@ class Worker
|
||||||
// Count active workers and compare them with a maximum value that depends on the load
|
// Count active workers and compare them with a maximum value that depends on the load
|
||||||
if (self::tooMuchWorkers()) {
|
if (self::tooMuchWorkers()) {
|
||||||
logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
|
logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
|
||||||
|
Lock::release('worker');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check free memory
|
// Check free memory
|
||||||
if ($a->min_memory_reached()) {
|
if ($a->min_memory_reached()) {
|
||||||
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
|
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
|
||||||
|
Lock::release('worker');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Lock::release('worker');
|
Lock::release('worker');
|
||||||
|
|
|
@ -1936,6 +1936,7 @@ class Item extends BaseObject
|
||||||
} else {
|
} else {
|
||||||
// This shouldn't happen.
|
// This shouldn't happen.
|
||||||
logger('Could not insert activity for URI ' . $item['uri'] . ' - should not happen');
|
logger('Could not insert activity for URI ' . $item['uri'] . ' - should not happen');
|
||||||
|
Lock::release('item_insert_activity');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($locked) {
|
if ($locked) {
|
||||||
|
|
|
@ -81,19 +81,33 @@ abstract class CacheTest extends DatabaseTest
|
||||||
'3_value1' => $this->instance->get('3_value1'),
|
'3_value1' => $this->instance->get('3_value1'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertTrue($this->instance->clear(false));
|
$this->assertTrue($this->instance->clear());
|
||||||
|
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'1_value1' => null,
|
'1_value1' => 'ipsum lorum1',
|
||||||
'1_value2' => null,
|
'1_value2' => 'ipsum lorum2',
|
||||||
'2_value1' => null,
|
'2_value1' => 'ipsum lorum3',
|
||||||
'3_value1' => null,
|
'3_value1' => 'ipsum lorum4',
|
||||||
], [
|
], [
|
||||||
'1_value1' => $this->instance->get('1_value1'),
|
'1_value1' => $this->instance->get('1_value1'),
|
||||||
'1_value2' => $this->instance->get('1_value2'),
|
'1_value2' => $this->instance->get('1_value2'),
|
||||||
'2_value1' => $this->instance->get('2_value1'),
|
'2_value1' => $this->instance->get('2_value1'),
|
||||||
'3_value1' => $this->instance->get('3_value1'),
|
'3_value1' => $this->instance->get('3_value1'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($this->instance->clear(false));
|
||||||
|
|
||||||
|
$this->assertEquals([
|
||||||
|
'1_value1' => null,
|
||||||
|
'1_value2' => null,
|
||||||
|
'2_value3' => null,
|
||||||
|
'3_value4' => null,
|
||||||
|
], [
|
||||||
|
'1_value1' => $this->instance->get('1_value1'),
|
||||||
|
'1_value2' => $this->instance->get('1_value2'),
|
||||||
|
'2_value3' => $this->instance->get('2_value3'),
|
||||||
|
'3_value4' => $this->instance->get('3_value4'),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,21 +8,9 @@ use Friendica\Core\Lock\CacheLockDriver;
|
||||||
|
|
||||||
class ArrayCacheLockDriverTest extends LockTest
|
class ArrayCacheLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Friendica\Core\Cache\IMemoryCacheDriver
|
|
||||||
*/
|
|
||||||
private $cache;
|
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
$this->cache = new ArrayCache();
|
return new CacheLockDriver(new ArrayCache());
|
||||||
return new CacheLockDriver($this->cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->cache->clear();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLockTTL()
|
public function testLockTTL()
|
||||||
|
|
|
@ -19,6 +19,7 @@ abstract class LockTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->instance = $this->getInstance();
|
$this->instance = $this->getInstance();
|
||||||
|
$this->instance->releaseAll();
|
||||||
|
|
||||||
// Reusable App object
|
// Reusable App object
|
||||||
$this->app = BaseObject::getApp();
|
$this->app = BaseObject::getApp();
|
||||||
|
@ -31,11 +32,18 @@ abstract class LockTest extends DatabaseTest
|
||||||
Config::set('system', 'theme', 'system_theme');
|
Config::set('system', 'theme', 'system_theme');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
$this->instance->releaseAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @small
|
* @small
|
||||||
*/
|
*/
|
||||||
public function testLock() {
|
public function testLock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->assertFalse($this->instance->isLocked('foo'));
|
||||||
|
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
$this->assertFalse($this->instance->isLocked('bar'));
|
$this->assertFalse($this->instance->isLocked('bar'));
|
||||||
}
|
}
|
||||||
|
@ -44,7 +52,8 @@ abstract class LockTest extends DatabaseTest
|
||||||
* @small
|
* @small
|
||||||
*/
|
*/
|
||||||
public function testDoubleLock() {
|
public function testDoubleLock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->assertFalse($this->instance->isLocked('foo'));
|
||||||
|
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
// We already locked it
|
// We already locked it
|
||||||
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
||||||
|
@ -54,7 +63,8 @@ abstract class LockTest extends DatabaseTest
|
||||||
* @small
|
* @small
|
||||||
*/
|
*/
|
||||||
public function testReleaseLock() {
|
public function testReleaseLock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->assertFalse($this->instance->isLocked('foo'));
|
||||||
|
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
$this->instance->releaseLock('foo');
|
$this->instance->releaseLock('foo');
|
||||||
$this->assertFalse($this->instance->isLocked('foo'));
|
$this->assertFalse($this->instance->isLocked('foo'));
|
||||||
|
@ -64,9 +74,9 @@ abstract class LockTest extends DatabaseTest
|
||||||
* @small
|
* @small
|
||||||
*/
|
*/
|
||||||
public function testReleaseAll() {
|
public function testReleaseAll() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
||||||
$this->instance->acquireLock('bar', 1);
|
$this->assertTrue($this->instance->acquireLock('bar', 1));
|
||||||
$this->instance->acquireLock('nice', 1);
|
$this->assertTrue($this->instance->acquireLock('nice', 1));
|
||||||
|
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
$this->assertTrue($this->instance->isLocked('bar'));
|
$this->assertTrue($this->instance->isLocked('bar'));
|
||||||
|
@ -83,9 +93,12 @@ abstract class LockTest extends DatabaseTest
|
||||||
* @small
|
* @small
|
||||||
*/
|
*/
|
||||||
public function testReleaseAfterUnlock() {
|
public function testReleaseAfterUnlock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->assertFalse($this->instance->isLocked('foo'));
|
||||||
$this->instance->acquireLock('bar', 1);
|
$this->assertFalse($this->instance->isLocked('bar'));
|
||||||
$this->instance->acquireLock('nice', 1);
|
$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->instance->releaseLock('foo');
|
$this->instance->releaseLock('foo');
|
||||||
|
|
||||||
|
@ -103,10 +116,12 @@ abstract class LockTest extends DatabaseTest
|
||||||
* @medium
|
* @medium
|
||||||
*/
|
*/
|
||||||
function testLockTTL() {
|
function testLockTTL() {
|
||||||
|
$this->assertFalse($this->instance->isLocked('foo'));
|
||||||
|
$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
|
// 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->instance->acquireLock('foo', 1, 1);
|
$this->assertTrue($this->instance->acquireLock('foo', 2, 1));
|
||||||
$this->instance->acquireLock('bar', 1, 3);
|
$this->assertTrue($this->instance->acquireLock('bar', 2, 3));
|
||||||
|
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
$this->assertTrue($this->instance->isLocked('bar'));
|
$this->assertTrue($this->instance->isLocked('bar'));
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
|
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
use Friendica\Core\Lock\CacheLockDriver;
|
use Friendica\Core\Lock\CacheLockDriver;
|
||||||
|
|
||||||
|
@ -12,20 +11,8 @@ use Friendica\Core\Lock\CacheLockDriver;
|
||||||
*/
|
*/
|
||||||
class MemcacheCacheLockDriverTest extends LockTest
|
class MemcacheCacheLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Friendica\Core\Cache\IMemoryCacheDriver
|
|
||||||
*/
|
|
||||||
private $cache;
|
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
$this->cache = CacheDriverFactory::create('memcache');
|
return new CacheLockDriver(CacheDriverFactory::create('memcache'));
|
||||||
return new CacheLockDriver($this->cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->cache->clear();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
|
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
use Friendica\Core\Lock\CacheLockDriver;
|
use Friendica\Core\Lock\CacheLockDriver;
|
||||||
|
|
||||||
|
@ -12,20 +11,8 @@ use Friendica\Core\Lock\CacheLockDriver;
|
||||||
*/
|
*/
|
||||||
class MemcachedCacheLockDriverTest extends LockTest
|
class MemcachedCacheLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Friendica\Core\Cache\IMemoryCacheDriver
|
|
||||||
*/
|
|
||||||
private $cache;
|
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
$this->cache = CacheDriverFactory::create('memcached');
|
return new CacheLockDriver(CacheDriverFactory::create('memcached'));
|
||||||
return new CacheLockDriver($this->cache);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->cache->clear();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
|
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
use Friendica\Core\Lock\CacheLockDriver;
|
use Friendica\Core\Lock\CacheLockDriver;
|
||||||
|
|
||||||
|
@ -12,21 +11,9 @@ use Friendica\Core\Lock\CacheLockDriver;
|
||||||
*/
|
*/
|
||||||
class RedisCacheLockDriverTest extends LockTest
|
class RedisCacheLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Friendica\Core\Cache\IMemoryCacheDriver
|
|
||||||
*/
|
|
||||||
private $cache;
|
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
$this->cache = CacheDriverFactory::create('redis');
|
return new CacheLockDriver(CacheDriverFactory::create('redis'));
|
||||||
return new CacheLockDriver($this->cache);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->cache->clear();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,26 +2,13 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
|
|
||||||
use Friendica\Core\Lock\SemaphoreLockDriver;
|
use Friendica\Core\Lock\SemaphoreLockDriver;
|
||||||
|
|
||||||
class SemaphoreLockDriverTest extends LockTest
|
class SemaphoreLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Friendica\Core\Lock\SemaphoreLockDriver
|
|
||||||
*/
|
|
||||||
private $semaphoreLockDriver;
|
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
$this->semaphoreLockDriver = new SemaphoreLockDriver();
|
return new SemaphoreLockDriver();
|
||||||
return $this->semaphoreLockDriver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->semaphoreLockDriver->releaseAll();
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLockTTL()
|
function testLockTTL()
|
||||||
|
|
Loading…
Reference in a new issue