LockDriverFixings

- release Locks in case of failures
- adding some cache tests
This commit is contained in:
Philipp Holzer 2018-09-06 08:11:18 +02:00
parent f148dcabc4
commit bd2b3b1ef5
No known key found for this signature in database
GPG Key ID: 58160D7D6AF942B6
4 changed files with 27 additions and 5 deletions

View File

@ -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;
} }

View File

@ -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');

View File

@ -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) {

View File

@ -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'),
]);
} }
/** /**